Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
5.14.2, 5.15.0
-
None
-
Doesn't matter
Description
When I enable Qt::AA_UseStyleSheetPropagationInWidgetStyles attribute, Qt Widgets stop propagating font and palette from the parent to the children. Here is an example code to reproduce the problem (activate the commented out line to see the bug):
#include <QtWidgets> int main(int argc, char* argv[]) { // Setting attribute prevents font and palette propagation from parent to child: // QApplication::setAttribute(Qt::AA_UseStyleSheetPropagationInWidgetStyles); QApplication a(argc, argv); a.setFont(QFont("Arial", 12)); // Default font a.setPalette(QPalette(Qt::red, {}, {}, {}, {}, {}, {})); // Default text color QGroupBox parent("Parent"); parent.setFont(QFont("Times New Roman", 18)); parent.setPalette(QPalette(Qt::yellow, {}, {}, {}, {}, {}, {})); QVBoxLayout layout(&parent); layout.addWidget(new QLabel("Child")); parent.show(); return a.exec(); }
I believe the problem lies in the QWidget::setParent() code here. I also believe that it can be fixed via replacing the if statement in the code I pointed out above with the code below:
if (useStyleSheetPropagationInWidgetStyles || (!testAttribute(Qt::WA_StyleSheet) && (!parent || !parent->testAttribute(Qt::WA_StyleSheet))))