A point is the most simple graphics object that can be drawn. It is a small spot on the window.

#!/usr/bin/python
# -*- coding: utf-8 -*- """
ZetCode PyQt4 tutorial In the example, we draw randomly 1000 red points
on the window. author: Jan Bodnar
website: zetcode.com
last edited: September 2011
""" import sys, random
from PyQt4 import QtGui, QtCore class Example(QtGui.QWidget): def __init__(self):
super(Example, self).__init__() self.initUI() def initUI(self): self.setGeometry(300, 300, 280, 170)
self.setWindowTitle('Points')
self.show() def paintEvent(self, e): qp = QtGui.QPainter()
qp.begin(self)
self.drawPoints(qp)
qp.end() def drawPoints(self, qp): qp.setPen(QtCore.Qt.red)
size = self.size() for i in range(1000):
x = random.randint(1, size.width()-1)
y = random.randint(1, size.height()-1)
qp.drawPoint(x, y) def main(): app = QtGui.QApplication(sys.argv)
ex = Example()
sys.exit(app.exec_()) if __name__ == '__main__':
main()

In our example, we draw randomly 1000 red points on the client area of the window.

qp.setPen(QtCore.Qt.red)

We set the pen to red colour. We use a predefined QtCore.Qt.red colour constant.

size = self.size()

Each time we resize the window, a paint event is generated. We get the current size of the window with the size() method. We use the size of the window to distribute the points all over the client area of the window.

qp.drawPoint(x, y)

We draw the point with the drawPoint() method.

Figure: Points

Drawing points的更多相关文章

  1. 配置OpenGL及第一个实例

    Windows环境下安装GLUT的步骤:1.将下载的压缩包解开,将得到5个文件2.在“我的电脑”中搜索“gl.h”,并找到其所在文件夹(如果是VS,则应该是其安装目录下面的“VC\PlatformSD ...

  2. Html5 touch event

    HTML5 for the Mobile Web: Touch Events POSTED BY RUADHAN - 15 AUG 2013 See also... Touch-friendly Dr ...

  3. High-speed Charting Control--MFC绘制图表(折线图、饼图、柱形图)控件

    原文地址:https://www.codeproject.com/articles/14075/high-speed-charting-control 本文翻译在CodeProject上的介绍(主要还 ...

  4. BrightScript 3D test - Roku (4)

    My initial attempt to port over an old Actionscript program, here it goes in main.brs. Library " ...

  5. ios 画板的使用

    由于项目需求需要用到一个画板功能,需要这个画板可以实时的画,并且需要保存画板点集合从一端发送给另一端 达到一个实时同步的功能,前后使用了三种方法,每一种都遇到各种坑(后面会提到,每一种方法的优缺点), ...

  6. Drawing Simple Polygon(Create Simple Polygon from unordered points by angle sorting)

    Keywords: 极角排序, Simple Polygon Generation Given set of points in the plane, your task is to draw a p ...

  7. [OpenCV] Samples 01: drawing

    基本的几何图形,标注功能. commondLineParser的使用参见:http://blog.csdn.net/u010305560/article/details/8941365 #includ ...

  8. Drawing Arc Using ArcSegment in XAML

    We can use the Arc XAML element to draw arcs in XAML. Besides drawing arcs using the Arc element, we ...

  9. LightOJ 1285 - Drawing Simple Polygon (几何,极角排序)

    1285 - Drawing Simple Polygon   PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: ...

随机推荐

  1. 51Nod1962 区间计数

    这题与之前那道区间最值的题非常类似,依旧是二分区间,然后统计跨过中间点的区间贡献. 我们要选出小于等于和小于的,这样就可以算出相等的区间长了. 复杂度O(nlogn) By:大奕哥 #include& ...

  2. Codeforces 839E Mother of Dragons(极大团)

    [题目链接] http://codeforces.com/contest/839/problem/E [题目大意] 现在有一些点,现在你有k的液体,随意分配给这些点, 当两个点有边相连的时候,他们能产 ...

  3. 斐波那契数列(Java实现)

    描述 一个斐波那契序列,F(0) = 0, F(1) = 1, F(n) = F(n-1) + F(n-2) (n>=2),根据n的值,计算斐波那契数F(n),其中0≤n≤1000. 输入 输入 ...

  4. 【转】代码混淆和apk反编译

    代码混淆 http://blog.csdn.net/vipzjyno1/article/details/21042823 apk反编译 http://blog.csdn.net/vipzjyno1/a ...

  5. Windows UWP开发系列 – RelativePanel

    RelativePanel是在Windows 10 UWP程序中引入的一种新的布局面板,它是通过附加属性设置元素间的位置关系来对实现布局的.一个简单的示例如下: <RelativePanel&g ...

  6. React事件初探

    作者:朱灵子 React 是一个 Facebook 和 Instagram 用来创建用户界面的 JavaScript 库.创造 React 是为了解决一个问题:构建随着时间数据不断变化的大规模应用程序 ...

  7. pytest文档7-pytest-html生成html报告

    前言 pytest-HTML是一个插件,pytest用于生成测试结果的HTML报告.兼容Python 2.7,3.6 pytest-html 1.github上源码地址[https://github. ...

  8. poj 3258 River Hopscotch 题解

    [题意] 牛要到河对岸,在与河岸垂直的一条线上,河中有N块石头,给定河岸宽度L,以及每一块石头离牛所在河岸的距离, 现在去掉M块石头,要求去掉M块石头后,剩下的石头之间以及石头与河岸的最小距离的最大值 ...

  9. 比較不错的一个ios找茬游戏源代码

    找茬游戏源代码 .这个是一款很不错的ios找茬游戏源代码,该游戏的兼容性很好的.并且还能够支持ipad和iphone.UI界面设计得也很美丽,游戏源代码真的是一款很完美.并且又很完整的一款休闲类的游戏 ...

  10. JNI字段描述符

    “([Ljava/lang/String;)V” 它是一种对函数返回值和参数的编码.这种编码叫做JNI字段描述符(JavaNative Interface FieldDescriptors).一个数组 ...