From 7293200ace12f4870b87bb6a1f5a22ef53bf52cd Mon Sep 17 00:00:00 2001 From: Aaron Kennedy Date: Sun, 28 Jun 2015 21:31:30 +1000 Subject: Add attribute to enable font and palette propagation in QSS. By default when using Qt Style Sheets, a widget does not inherit its font and palette from its parent widget. With the Qt::AA_UseStyleSheetPropagationInWidgetStyles application attribute set, propagation when using Qt Style Sheets behaves like it does with regular QWidget::setPalette() and QWidget::setFont() calls. [ChangeLog][QtWidgets] Added the Qt::AA_UseStyleSheetPropagationInWidgetStyles attribute which enables font and palette propagation for Qt Style Sheets. Task-number: QTBUG-37580 Change-Id: I3038c13d61e32625a1a05291c5394eaefd376a68 Reviewed-by: Samuel Nevala Reviewed-by: Lars Knoll --- .../doc/snippets/code/doc_src_stylesheet.cpp | 4 ++++ .../doc/src/widgets-and-layouts/stylesheet.qdoc | 22 ++++++++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) (limited to 'src/widgets/doc') diff --git a/src/widgets/doc/snippets/code/doc_src_stylesheet.cpp b/src/widgets/doc/snippets/code/doc_src_stylesheet.cpp index a937498fe5..01f4c528a2 100644 --- a/src/widgets/doc/snippets/code/doc_src_stylesheet.cpp +++ b/src/widgets/doc/snippets/code/doc_src_stylesheet.cpp @@ -138,3 +138,7 @@ emailEdit->setProperty("mandatoryField", true); QSpinBox *ageSpinBox = new QSpinBox(this); ageSpinBox->setProperty("mandatoryField", true); //! [95] + +//! [96] +qApp->setAttribute(Qt::AA_UseStyleSheetPropagationInWidgetStyles, true); +//! [97] diff --git a/src/widgets/doc/src/widgets-and-layouts/stylesheet.qdoc b/src/widgets/doc/src/widgets-and-layouts/stylesheet.qdoc index fc3ac345a8..bea1a6e657 100644 --- a/src/widgets/doc/src/widgets-and-layouts/stylesheet.qdoc +++ b/src/widgets/doc/src/widgets-and-layouts/stylesheet.qdoc @@ -492,9 +492,9 @@ \section1 Inheritance In classic CSS, when font and color of an item is not explicitly set, - it gets automatically inherited from the parent. When using Qt Style Sheets, - a widget does \b{not} automatically inherit its font and color setting - from its parent widget. + it gets automatically inherited from the parent. By default, when using + Qt Style Sheets, a widget does \b{not} automatically inherit its font + and color setting from its parent widget. For example, consider a QPushButton inside a QGroupBox: @@ -507,9 +507,23 @@ \snippet code/doc_src_stylesheet.cpp 25 - In contrast, setting a font and propagate using QWidget::setFont() and + In contrast, setting a font and palette using QWidget::setFont() and QWidget::setPalette() propagates to child widgets. + If you would prefer that the font and palette propagate to child widgets, + you can set the Qt::AA_UseStyleSheetPropagationInWidgetStyles flag, like + this: + + Usage: + \snippet code/doc_src_stylesheet.cpp 96 + + When the widget-style font and palette propagation is enabled, font and + palette changes made through Qt Style Sheets will behave as though the + user had manually called the corresponding QWidget::setPalette() and + QWidget::setFont() methods on all of the QWidgets targeted by the style + sheet. If this would have caused propagation in C++, it will cause + propagation in style sheets and visa versa. + \section1 Widgets Inside C++ Namespaces The Type Selector can be used to style widgets of a particular type. For -- cgit v1.2.3