I am studing QWidget deeply.
Since Qt 4.1, the contents of parent widgets are propagated by default to each of their children as long as WA_PaintOnScreen is not set. Custom widgets can be written to take advantage of this feature by updating irregular regions (to create non-rectangular child widgets), or painting with colors that have less than full alpha component. The following diagram shows how attributes and properties of a custom widget can be fine-tuned to achieve different effects.
I set this attribute to True, but the contents of parent widgets seem to be propagated. I can't understand what this attribute is...
And also here.
Set the WA_PaintOnScreen attribute to enforce a native window (this implies 3).
What is the role of WA_PaintOnScreen? How can I look the effect? Which range of the contens of parentWidget?
from PySide6.QtWidgets import QWidget, QLabel, QApplication from PySide6.QtGui import QPixmap, QPainter, QFont, QColor, QPolygon, QPalette, QRegion from PySide6.QtCore import Qt, QRect, QPoint import sys class ChildWidget(QWidget): def __init__(self, parent=None): super().__init__(parent) self.setGeometry(0, 0, 125, 100) def paintEvent(self, event): painter = QPainter() painter.begin(self) brush = painter.brush() brush.setColor(Qt.white) brush.setStyle(Qt.SolidPattern) painter.setBrush(brush) painter.drawRect(self.rect()) brush = painter.brush() brush.setColor(Qt.red) brush.setStyle(Qt.DiagCrossPattern) painter.setBrush(brush) painter.drawRect(self.rect()) #propagated in spite of Qt.WA_PaintOnScreen print(painter.font()) painter.end() return super().paintEvent(event) class ParentWidget(QWidget): def __init__(self, parent=None): super().__init__(parent) self.setAttribute(Qt.WA_PaintOnScreen, True) self.childWidget = ChildWidget(parent=self) self.childWidget.move(100, 100) self.childWidget.repaint() self.setFont(QFont("Times New Roman", 18)) def main(): app = QApplication() w = ParentWidget() w.show() sys.exit(app.exec()) if __name__ == "__main__": main()