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. 全景图从拍摄到 online

    全景图从拍摄到 online Panorama, CSS3, Canvas, 3D 2015-11-04 拍摄设备 照片拼接 制作 3D Cube Demo 拍摄设备 电动自动全景云台 Gigapan ...

  2. Java并发(十一):Condition条件

    先做总结: 1.为什么使用Condition条件? synchronized配合Object的wait().notify()系列方法可以实现等待/通知模式. Lock提供了条件Condition,对线 ...

  3. bzoj2200道路和航线

    试题描述 Farmer John 正在一个新的销售区域对他的牛奶销售方案进行调查.他想把牛奶送到 T (1≤T≤2.5×10^4)个城镇 ,编号为 1 到 T.这些城镇之间通过 R 条道路(编号为 1 ...

  4. [转]Android Service完全解析,关于服务你所需知道的一切

      目录(?)[+] Android Service完全解析,关于服务你所需知道的一切(上) 分类: Android疑难解析2013-10-31 08:10 6451人阅读 评论(39) 收藏 举报 ...

  5. MySQL 之 Index Condition Pushdown(ICP)

    简介 Index Condition Pushdown (ICP)是MySQL 5.6 版本中的新特性,是一种在存储引擎层使用索引过滤数据的一种优化方式. 当关闭ICP时,index 仅仅是data ...

  6. Android中的数据存储(一):SharedPreferences 2017-05-24 10:35 64人阅读 评论(1) 收藏

    SharedPreferences 这是本人(菜鸟)学习android数据存储时接触的有关SharedPreferences的知识以及本人自己写的一个简单地demo,为初学者学习和使用SharedPr ...

  7. Git与SVN

    http://www.nowamagic.net/academy/detail/48160207 前面提到,Linus一直痛恨CVS及SVN这些集中式的版本控制系统,为什么呢?Git是分布式版本控制系 ...

  8. Current mirror drives multiple LEDs from a low supply voltage

    Driving LEDs at a regulated current from low supply voltages can be difficult because minimal overhe ...

  9. WM-N-BM-09 WM-N-BM-14

    USI Delivers WICED Module to Gain Great Success Customers Broadcom’s Wireless Internet Connectivity ...

  10. SourceInsight中文字体

    转载自: http://blog.chinaunix.net/uid-29094179-id-3889999.html 1.正确显示中文注释 1)Options->Style Propertie ...