zoukankan      html  css  js  c++  java
  • Colours

    A colour is an object representing a combination of Red, Green, and Blue (RGB) intensity values. Valid RGB values are in the range from 0 to 255. We can define a colour in various ways. The most common are RGB decimal values or hexadecimal values. We can also use an RGBA value which stands for Red, Green, Blue, and Alpha. Here we add some extra information regarding transparency. Alpha value of 255 defines full opacity, 0 is for full transparency, e.g. the colour is invisible.

    #!/usr/bin/python
    # -*- coding: utf-8 -*-
    
    """
    ZetCode PyQt4 tutorial 
    
    This example draws three rectangles in three
    different colours. 
    
    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, 350, 100)
            self.setWindowTitle('Colours')
            self.show()
    
        def paintEvent(self, e):
    
            qp = QtGui.QPainter()
            qp.begin(self)
            self.drawRectangles(qp)
            qp.end()
            
        def drawRectangles(self, qp):
          
            color = QtGui.QColor(0, 0, 0)
            color.setNamedColor('#d4d4d4')
            qp.setPen(color)
    
            qp.setBrush(QtGui.QColor(200, 0, 0))
            qp.drawRect(10, 15, 90, 60)
    
            qp.setBrush(QtGui.QColor(255, 80, 0, 160))
            qp.drawRect(130, 15, 90, 60)
    
            qp.setBrush(QtGui.QColor(25, 0, 90, 200))
            qp.drawRect(250, 15, 90, 60)
                  
            
    def main():
        
        app = QtGui.QApplication(sys.argv)
        ex = Example()
        sys.exit(app.exec_())
    
    
    if __name__ == '__main__':
        main()
    

    In our example, we draw 3 coloured rectangles.

    color = QtGui.QColor(0, 0, 0)
    color.setNamedColor('#d4d4d4')
    

    Here we define a colour using a hexadecimal notation.

    qp.setBrush(QtGui.QColor(200, 0, 0))
    qp.drawRect(10, 15, 90, 60)
    

    Here we define a brush and draw a rectangle. A brush is an elementary graphics object which is used to draw the background of a shape. The drawRect() method accepts four parameters. The first two are x and y values on the axis. The third and fourth parameters are the width and height of the rectangle. The method draws the rectangle using the current pen and brush.

    ColoursFigure: Colours

  • 相关阅读:
    CISCO实验记录九:NAT地址转换
    CISCO实验记录八:ACL访问控制
    【零基础】风格迁移之deep-painterly-harmonization的安装和使用
    CISCO实验记录七:OSPF
    【零基础】看懂“深度学习”的优势
    数学专业各学科视频网址
    Flash网站Loading制作
    30张图 讲述真实的人性
    【UXPA工作坊小记】郎学明:做更“有用”的用户研究
    科学训练传播训练营///第一期:科学问题的复杂性///参后感觉
  • 原文地址:https://www.cnblogs.com/hushaojun/p/4436943.html
Copyright © 2011-2022 走看看