Quantcast
Channel: Active questions tagged qpainter - Stack Overflow
Viewing all articles
Browse latest Browse all 58

How to restore QPainter.setBrush

$
0
0

I need to paint three rectangles (just for example) one after another in painEvent method. I can't find the answer why after setting Brush for first rectangle and then restoring QPainter with restore command it is not restored. Second rectangle must be empty, but it is filled with first rectangle color. I would appreciate for any advice. Thank you.

from PyQt5.QtWidgets import QWidget, QApplicationfrom PyQt5.QtGui import QPainter, QColor, QBrushimport sysclass Rectangles(QWidget):    def __init__(self):        super().__init__()        self.initUI()    def initUI(self):        self.setGeometry(300, 300, 350, 100)        self.show()    def paintEvent(self, event):        qp = QPainter()        qp.begin(self)        self.drawRectangles(qp)        qp.end()    def drawRectangles(self, qp):        qp.setPen(QColor(0, 0, 0))        qp.setBrush(QColor(255, 0, 0))                qp.drawRect(10, 15, 90, 60)        qp.restore()        qp.drawRect(130, 15, 90, 60)        qp.setBrush(QColor(0, 0 , 255))        qp.drawRect(250, 15, 90, 60)def main():    app = QApplication(sys.argv)    ex = Rectangles()    app.exec()if __name__ == '__main__':    main()

Viewing all articles
Browse latest Browse all 58

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>