Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-86501

QWidget::setParent doesn't propagate font and palette from parent to children when Qt::AA_UseStyleSheetPropagationInWidgetStyles attribute is enabled

    XMLWordPrintable

Details

    • All

    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))))
      

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            kozmon Ömer Göktaş
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes