Drawing points
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的更多相关文章
- 配置OpenGL及第一个实例
Windows环境下安装GLUT的步骤:1.将下载的压缩包解开,将得到5个文件2.在“我的电脑”中搜索“gl.h”,并找到其所在文件夹(如果是VS,则应该是其安装目录下面的“VC\PlatformSD ...
- Html5 touch event
HTML5 for the Mobile Web: Touch Events POSTED BY RUADHAN - 15 AUG 2013 See also... Touch-friendly Dr ...
- High-speed Charting Control--MFC绘制图表(折线图、饼图、柱形图)控件
原文地址:https://www.codeproject.com/articles/14075/high-speed-charting-control 本文翻译在CodeProject上的介绍(主要还 ...
- BrightScript 3D test - Roku (4)
My initial attempt to port over an old Actionscript program, here it goes in main.brs. Library " ...
- ios 画板的使用
由于项目需求需要用到一个画板功能,需要这个画板可以实时的画,并且需要保存画板点集合从一端发送给另一端 达到一个实时同步的功能,前后使用了三种方法,每一种都遇到各种坑(后面会提到,每一种方法的优缺点), ...
- 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 ...
- [OpenCV] Samples 01: drawing
基本的几何图形,标注功能. commondLineParser的使用参见:http://blog.csdn.net/u010305560/article/details/8941365 #includ ...
- 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 ...
- LightOJ 1285 - Drawing Simple Polygon (几何,极角排序)
1285 - Drawing Simple Polygon PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: ...
随机推荐
- 是否排序好了 Exercise07_19
import java.util.Scanner; import java.util.Arrays; /** * @author 冰樱梦 * 时间2018年12月 * 题目:是否排序好了 * */ p ...
- 【8.15校内测试】【队列】【manacher】
dp??不能确定转移状态.考虑用优先队列储存最优决策点,可是发现当前选择最优不能保证最后最优,在后面可以将之前用过的替换过来. 比如数据: 3 5 4 6 只储存a[i]来决策不能延展到后面的状态,因 ...
- UVA 10531 Maze Statistics 迷宫统计 迷宫插头DP 四联通 概率
题意: 有一个N*M的图,每个格子有独立概率p变成障碍物.你要从迷宫左上角走到迷宫右下角.求每个格子成为一个有解迷宫中的障碍物的概率.N <= 5,M <= 6 分析: 这真是一道好题,网 ...
- Codeforces Round #299 (Div. 2) A. Tavas and Nafas 水题
A. Tavas and Nafas Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/535/pr ...
- csv文件导入到mysql
如何将csv文件导入到mysql数据库呢,方法有很多但最简单粗暴的方法还是用sql语句啦,像下面这样. LOAD DATA LOCAL INFILE 'csv文件路径' INTO TABLE 数据表名 ...
- CentOS的rpm常用命令(转)
一.RPM 安装操作 命令: rpm -i 需要安装的包文件名 举例如下: rpm -i example.rpm 安装 example.rpm 包: rpm -iv example.rpm 安装 ex ...
- MYSQL GDB SHELL
http://blog.163.com/xychenbaihu@yeah/blog/static/132229655201141165216974/
- Assembly.Load()方法,Assembly.LoadFrom()方法,Assembly.LoadFile()方法的区别!
参考: http://www.cnblogs.com/benwu/archive/2009/10/24/1589096.html http://www.cnblogs.com/xuefeng1982/ ...
- jquery-问题解答
1.var v = $('.summer-input:input').val(); //依据class获取input 2.var v = $('input[name=user\\.name]').va ...
- 内核镜像zImage是如何生成的
转载:内核镜像zImage是如何生成的 内核镜像zImage是如何生成的 前面两篇文章介绍了vmlinux 文件生成,这个文件必然是核心的linux内核,但是它是ELF格式的文件,其中包含了可执行的二 ...