zoukankan      html  css  js  c++  java
  • 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.

    PointsFigure: Points

  • 相关阅读:
    SQL——with as 临时表
    SQL 在数据库中查找拥有此列名的所有表
    帆软报表(finereport)鼠标悬停背景变色
    帆软报表(finereport)控件背景色更改
    帆软报表(finereport)使用Event 事件对象 (target)修改提示框样式
    微信indexOf不能使用,代替方式
    基础知识
    VUE知识点
    银行金额处理
    flex-1
  • 原文地址:https://www.cnblogs.com/hushaojun/p/4436939.html
Copyright © 2011-2022 走看看