• QtGui.QBrush


    The QtGui.QBrush is an elementary graphics object. It is used to paint the background of graphics shapes, such as rectangles, ellipses, or polygons. A brush can be of three different types: a predefined brush, a gradient, or a texture pattern.

    #!/usr/bin/python
    # -*- coding: utf-8 -*-
    
    """
    ZetCode PyQt4 tutorial 
    
    This example draws 9 rectangles in different
    brush styles.
    
    author: Jan Bodnar
    website: zetcode.com 
    last edited: September 2011
    """
    
    import sys
    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, 355, 280)
            self.setWindowTitle('Brushes')
            self.show()
    
        def paintEvent(self, e):
    
            qp = QtGui.QPainter()
            qp.begin(self)
            self.drawBrushes(qp)
            qp.end()
            
        def drawBrushes(self, qp):
          
            brush = QtGui.QBrush(QtCore.Qt.SolidPattern)
            qp.setBrush(brush)
            qp.drawRect(10, 15, 90, 60)
    
            brush.setStyle(QtCore.Qt.Dense1Pattern)
            qp.setBrush(brush)
            qp.drawRect(130, 15, 90, 60)
    
            brush.setStyle(QtCore.Qt.Dense2Pattern)
            qp.setBrush(brush)
            qp.drawRect(250, 15, 90, 60)
    
            brush.setStyle(QtCore.Qt.Dense3Pattern)
            qp.setBrush(brush)
            qp.drawRect(10, 105, 90, 60)
    
            brush.setStyle(QtCore.Qt.DiagCrossPattern)
            qp.setBrush(brush)
            qp.drawRect(10, 105, 90, 60)
    
            brush.setStyle(QtCore.Qt.Dense5Pattern)
            qp.setBrush(brush)
            qp.drawRect(130, 105, 90, 60)
    
            brush.setStyle(QtCore.Qt.Dense6Pattern)
            qp.setBrush(brush)
            qp.drawRect(250, 105, 90, 60)
    
            brush.setStyle(QtCore.Qt.HorPattern)
            qp.setBrush(brush)
            qp.drawRect(10, 195, 90, 60)
    
            brush.setStyle(QtCore.Qt.VerPattern)
            qp.setBrush(brush)
            qp.drawRect(130, 195, 90, 60)
    
            brush.setStyle(QtCore.Qt.BDiagPattern)
            qp.setBrush(brush)
            qp.drawRect(250, 195, 90, 60)
                  
            
    def main():
        
        app = QtGui.QApplication(sys.argv)
        ex = Example()
        sys.exit(app.exec_())
    
    
    if __name__ == '__main__':
        main()
    

    In our example, we draw nine different rectangles.

    brush = QtGui.QBrush(QtCore.Qt.SolidPattern)
    qp.setBrush(brush)
    qp.drawRect(10, 15, 90, 60)
    

    We define a brush object. We set it to the painter object and draw the rectangle by calling thedrawRect() method.

    BrushesFigure: Brushes

  • 相关阅读:
    数据结构基础(二)排序算法
    数据结构基础(一) 时间空间复杂度分析
    347. Top K Frequent Elements, O(N) solution
    409. Longest Palindrome
    556. Next Greater Element III
    CH0103 最短Hamilton路径(状压DP)
    牛客OI周赛13-提高组A-0还是1(简单DP)
    Codeforces Round #678 (Div. 2) C. Binary Search(二分查找/思维/排列组合)
    Codeforces Round #677 (Div. 3) A-E
    函数实现复合命题的计算及判断两个命题是否等值——中缀表达式转后缀表达式
  • 原文地址:https://www.cnblogs.com/hushaojun/p/4437241.html
Copyright © 2020-2023  润新知