diff options
author | Aaron Kennedy <aaron.kennedy+qt@gmail.com> | 2018-05-09 23:04:00 +1000 |
---|---|---|
committer | Aaron Kennedy <aaron.kennedy+qt@gmail.com> | 2018-05-23 05:22:06 +0000 |
commit | c83ea33ceb95aa705085a970ce619d37439c98cb (patch) | |
tree | b1202420cdd5df6e849ec302f8e363a569ad509a /src/widgets/styles | |
parent | 91f12fe62b001e8e00682eb988f74a1792573cb7 (diff) |
Add attribute to indicate a widget was the target of a style sheet
Qt already has the widget attribute WA_StyleSheet to which indicates that
a widget was subject to a style sheet, but it doesn't indicate that the
widget was actually affected by the style sheet. For example, an application
style sheet will set the WA_StyleSheet attribute on all widgets, even if it
only targets QPushButtons. The WA_StyleSheetTarget new attribute pairs with
WA_StyleSheet to give this extra information.
[ChangeLog][QtWidgets] Added the Qt::WA_StyleSheetTarget attribute to
indicate that a widget was affected by a style sheet.
Change-Id: I7cca18ddec8fbb69f294ae2ef990672a5f4f1d83
Reviewed-by: Gabriel de Dietrich <gabriel.dedietrich@qt.io>
Reviewed-by: Sérgio Martins <sergio.martins@kdab.com>
Diffstat (limited to 'src/widgets/styles')
-rw-r--r-- | src/widgets/styles/qstylesheetstyle.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp index 1a6a4e303b..3f0b6fbfda 100644 --- a/src/widgets/styles/qstylesheetstyle.cpp +++ b/src/widgets/styles/qstylesheetstyle.cpp @@ -530,6 +530,8 @@ public: const QStyleSheetGeometryData *geometry() const { return geo; } const QStyleSheetPositionData *position() const { return p; } + bool hasModification() const; + bool hasPalette() const { return pal != 0; } bool hasBackground() const { return bg != 0 && (!bg->pixmap.isNull() || bg->brush.style() != Qt::NoBrush); } bool hasGradientBackground() const { return bg && bg->brush.style() >= Qt::LinearGradientPattern @@ -1444,6 +1446,21 @@ void QRenderRule::configurePalette(QPalette *p, QPalette::ColorGroup cg, const Q p->setBrush(cg, QPalette::AlternateBase, pal->alternateBackground); } +bool QRenderRule::hasModification() const +{ + return hasPalette() || + hasBackground() || + hasGradientBackground() || + !hasNativeBorder() || + !hasNativeOutline() || + hasBox() || + hasPosition() || + hasGeometry() || + hasImage() || + hasFont || + !styleHints.isEmpty(); +} + /////////////////////////////////////////////////////////////////////////////// // Style rules #define OBJECT_PTR(x) (static_cast<QObject *>(x.ptr)) @@ -2823,6 +2840,9 @@ void QStyleSheetStyle::polish(QWidget *w) #endif QRenderRule rule = renderRule(w, PseudoElement_None, PseudoClass_Any); + + w->setAttribute(Qt::WA_StyleSheetTarget, rule.hasModification()); + if (rule.hasDrawable() || rule.hasBox()) { if (w->metaObject() == &QWidget::staticMetaObject #if QT_CONFIG(itemviews) @@ -2909,6 +2929,7 @@ void QStyleSheetStyle::unpolish(QWidget *w) w->setProperty("_q_stylesheet_minh", QVariant()); w->setProperty("_q_stylesheet_maxw", QVariant()); w->setProperty("_q_stylesheet_maxh", QVariant()); + w->setAttribute(Qt::WA_StyleSheetTarget, false); w->setAttribute(Qt::WA_StyleSheet, false); QObject::disconnect(w, 0, this, 0); #if QT_CONFIG(scrollarea) |