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

  • 相关阅读:
    网页中的图片查看器viewjs使用
    检测和删除多余无用的css
    网页中插入视频的方案
    WebSocket使用教程
    JS+CSS简单实现DIV遮罩层显示隐藏【转藏】
    使用GPS经纬度定位附近地点(某一点范围内查询)
    使用SQL Server Management Studio 创建数据库备份作业
    SVN trunk(主线) branch(分支) tag(标记) 用法详解和详细操作步骤
    关于LINQ方方面面的入门、进阶、深入的文章。
    LINQ体验(7)——LINQ to SQL语句之Group By/Having和Exists/In/Any/All/Contains
  • 原文地址:https://www.cnblogs.com/hushaojun/p/4437241.html
Copyright © 2011-2022 走看看