Achtergrond-patronen Brushes

Op deze pagina:

    Brushes worden gebruikt om de achtergrond mee te schilderen, het zijn patronen.

    
    #!/usr/bin/python3
    # -*- coding: utf-8 -*-
    
    import sys
    from PyQt5 import QtCore
    from PyQt5.QtWidgets import QApplication
    from PyQt5.QtWidgets import QWidget
    from PyQt5.QtGui import QPainter, QBrush
    
    class Venster(QWidget):
    
        def __init__(self):
            super(Venster, self).__init__()
    
            self.initUI()
    
        def initUI(self):
    
            self.setGeometry(400, 400, 390, 280)
            self.setWindowTitle('Patronen')
            self.show()
    
        def paintEvent(self, e):
    
            qp = QPainter()
            qp.begin(self)
            self.drawBrushes(qp)
            qp.end()
    
        def drawBrushes(self, qp):
    
            lengte = 100
            breedte = 60
            k1 = 20
            k2 = 150
            k3 = 270
            r1 = 20
            r2 = 110
            r3 = 200
    
            brush = QBrush(QtCore.Qt.SolidPattern)
            qp.setBrush(brush)
            qp.drawRect(k1, r1, lengte, breedte)
    
            brush.setStyle(QtCore.Qt.Dense1Pattern)
            qp.setBrush(brush)
            qp.drawRect(k2, r1, lengte, breedte)
    
            brush.setStyle(QtCore.Qt.Dense2Pattern)
            qp.setBrush(brush)
            qp.drawRect(k3, r1, lengte, breedte)
    
            brush.setStyle(QtCore.Qt.Dense3Pattern)
            qp.setBrush(brush)
            qp.drawRect(k1, r2, lengte, breedte)
    
            brush.setStyle(QtCore.Qt.DiagCrossPattern)
            qp.setBrush(brush)
            qp.drawRect(k1, r2, lengte, breedte)
    
            brush.setStyle(QtCore.Qt.Dense5Pattern)
            qp.setBrush(brush)
            qp.drawRect(k2, r2, lengte, breedte)
    
            brush.setStyle(QtCore.Qt.Dense6Pattern)
            qp.setBrush(brush)
            qp.drawRect(k3, r2, lengte, breedte)
    
            brush.setStyle(QtCore.Qt.HorPattern)
            qp.setBrush(brush)
            qp.drawRect(k1, r3, lengte, breedte)
    
            brush.setStyle(QtCore.Qt.VerPattern)
            qp.setBrush(brush)
            qp.drawRect(k2, r3, lengte, breedte)
    
            brush.setStyle(QtCore.Qt.BDiagPattern)
            qp.setBrush(brush)
            qp.drawRect(k3, r3, lengte, breedte)
    
    def main():
    
        app = QApplication(sys.argv)
        window = Venster()
        sys.exit(app.exec())
    
    if __name__ == '__main__':
        main()
    

    patronen

     

    Verwante artikelen