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. redis细节

    Redis对于Linux是官方支持的,安装和使用没有什么好说的,普通使用按照官方指导,5分钟以内就能搞定.详情请参考: http://redis.io/download 但有时候又想在windows下 ...

  2. windows server 2008 r2, 每隔一段时间自动关机

      前段时间在做Exchange 2010测试的时候,由于windows server 2008  r2试用过期,开机后二个小时就会自动关机,可是我又不想重装系统,加为那样我可能需要重装好多东西,包括 ...

  3. SilverLight学习笔记--使用WebClient实现通讯(一)(上传和下载字符串数据)

    一.什么是WebClient类   1.基本知识    WebClient类是Mircsoft在.NET框架下提供的向 URI 标识的资源发送数据和从 URI 标识的资源接收数据的公共方法.通过这个类 ...

  4. ADC Power Supplies

    http://www.planetanalog.com/author.asp?section_id=3041&doc_id=563055 Jonathan Harris, Product Ap ...

  5. spring boot配置springMVC拦截器

    spring boot通过配置springMVC拦截器 配置拦截器比较简单, spring boot配置拦截器, 重写preHandle方法. 1.配置拦截器: 2重写方法 这样就实现了拦截器. 其中 ...

  6. jdk8十大特性并代码demo(转)

    一.十大特性 1.Lambda表达式 2.Stream函数式操作流元素集合 3.接口新增:默认方法与静态方法 4.方法引用,与Lambda表达式联合使用 5.引入重复注解 6.类型注解 7.最新的Da ...

  7. (windows)一台电脑上安装两个Mysql服务

    原文:https://my.oschina.net/u/1472917/blog/410732 最近需要在一台电脑上安装两个Mysql服务,需求稍微有些奇怪,但确实很必要.本人原本为了本机测试Word ...

  8. 幸福框架:用户想看到的操作日志也要使用AOP吗?

    背景 日志无论是对于开发人员.运维人员和最终用户都是一笔财富,是不是所有类型的日志都要AOP呢?本着交流的目的,这里先说一些看法,希望大家多批评. 常见的日志类型 异常日志 概念:记录异常的日志. 考 ...

  9. python笔记21-列表生成式

    前言 python里面[]表示一个列表,快速生成一个列表可以用range()函数来生成. 对列表里面的数据进行运算和操作,生成新的列表最高效快速的办法,那就是列表生成式了. range() 1.一个连 ...

  10. 使用tortoisegit访问git@oschina

    转自:http://www.3lian.com/edu/2014/01-03/121350.html 首先,如果你想使用git@oschina ,你的电脑上必须先有git工具:你可以从这里获取谷歌提供 ...