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

最新文章

  1. VB6SP6极度精简兼容绿色版
  2. bat批处理文件启动Eclipse和ivy本地仓库的配置
  3. shell切割日志脚本
  4. EditPlus保存文件时不生成其备份文件的方法
  5. 基于MVC和Bootstrap的权限框架解决方案 一.搭建HTML
  6. Unity 使用Plugins接入安卓SDK 基础篇
  7. Eclipse 配置运行Spark
  8. Apache 配置小技巧
  9. metasploit渗透测试魔鬼训练营环境
  10. 微软SSAS 错误 Internal error: Invalid enumeration value. Please call customer support! 不是此元素的有效值。
  11. c/c++ const关键字
  12. openstack 之~keystone之网关协议
  13. 来自极客头条的 35 个 Java 代码性能优化总结
  14. 关于Virtual Box虚拟机里的系统不能启动的解决方法
  15. 中点Brehensam画圆算法
  16. [USACO08NOV]Cheering up the Cow
  17. [整理]VS2010中如何添加“依赖","库目录","包含目录"
  18. Asp.net处理程序(第六篇)
  19. word2vec参数
  20. Element.getBoundingClientRect()

热门文章

  1. CodeForces 1063B. Labyrinth 性质
  2. 【最小生成树】BZOJ1682[Usaco2005 Mar]-Out of Hay 干草危机
  3. web.xml2.3配置需要注意的顺序问题
  4. 62.COUNT(递归算法)--数的划分变式题型
  5. C++ -- STL泛型编程(二)之set
  6. BZOJ 4443: [Scoi2015]小凸玩矩阵 最大流
  7. leetcode132. Palindrome Partitioning II
  8. python - 在Windows系统中安装Pygame及导入Eclipse
  9. MySQL单表恢复方法
  10. NSDictionary , NSMutableDictionary, NSMutableDictionary 和 NSMutableSet)相当于java的map、set