1 Attachment(s)
Unexpected Offset in paintEvent
Does anybody know, why the Rect drawn in the paintEvent does not cover the exact area of my QWidget but instead starts at an weird offset?
Code:
def __init__(self):
super().__init__()
pal.
setColor(QPalette.
Window, Qt.
magenta) self.setAutoFillBackground(True)
self.setPalette(pal)
def paintEvent(self, event):
opt.initFrom(self)
painter.setBrush( Qt.red )
painter.drawRect(self.geometry().x(), self.geometry().y(), self.geometry().width(), self.geometry().height())
def __init__(self):
super().__init__()
pal.
setColor(QPalette.
Window, Qt.
yellow) self.setAutoFillBackground(True)
self.setPalette(pal)
def paintEvent(self, event):
painter.setBrush( Qt.green )
painter.drawRect(self.x(), self.y(), self.width(), self.height())
def __init__(self):
super().__init__()
self.setAutoFillBackground(True)
self.setPalette(pal)
def paintEvent(self, event):
painter.setBrush( Qt.blue )
painter.drawRect(self.x(), self.y(), self.width(), self.height())
def main():
containerWidget = ContainerWidget()
containerWidget.resize(800,600)
containerLayout.setSpacing(0)
containerLayout.setContentsMargins(0,0,0,0)
containerWidget.show()
sys.exit(app.exec_())
if __name__ == "__main__":
main()
Attachment 13600
Re: Unexpected Offset in paintEvent
You are using the QWidget::geometry() to paint the rect instead of the widget's position and size (QWidget::rect())