summaryrefslogtreecommitdiffstats
path: root/src/widgets
diff options
context:
space:
mode:
authorVolker Hilsheimer <volker.hilsheimer@qt.io>2020-02-19 14:11:12 +0100
committerVolker Hilsheimer <volker.hilsheimer@qt.io>2020-02-20 08:04:47 +0100
commit1821f5163d160ccd5faf9c4b995e72a7ed762c9a (patch)
tree86582bb13bfd86606b47715b9f9259d0a8a20540 /src/widgets
parentd928beb024c240b37d35d2c53f25648c99a484b4 (diff)
Fix font and palette propagation for themed children created at runtime
Widgets have a default palette and font that is influenced by several factors: theme, style, QApplication-wide overrides, and the parent's. If an application sets a font or palette on a parent, then widgets inherit those settings, no matter when they are added to the parent. The bug is that this is not true for widgets that have an application- wide override defined by the platform theme. For those, we need to merge parent palette and font attributes with the theme, and this is currently not done correctly, as the respective masks are not merged and inherited. This change fixes this for fonts and palettes. Children are inheriting their parent's inheritance masks, combined with the mask for the attributes set explicitly on the parent. This makes the font and palette resolving code correctly adopt those attributes that are set explicily, while leaving everything else as per the theme override. The test verifies that this works for children and grand children added to a widget that has a palette or font set, both when themed and unthemed. Children with own entries don't inherit from parent. The QFont::resetFont test had to be changed, as it was testing the wrong behavior. If the child would be added to the parent before the font property was set, then the test would have failed. Since this change makes sure that children inherit fonts in the same way, no matter on when they are added to their parent, the test is now modified to cover both cases, and ensures that they return identical results. [ChangeLog][QtWidgets][QWidget] Fonts and palette settings are inherited by children from their parents even if the children have application- wide platform theme overrides. Change-Id: I179a652b735e85bba3fafc30098d08d61684f488 Fixes: QTBUG-82125 Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io> Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Vitaly Fanaskov <vitaly.fanaskov@qt.io>
Diffstat (limited to 'src/widgets')
-rw-r--r--src/widgets/kernel/qwidget.cpp11
-rw-r--r--src/widgets/kernel/qwidget_p.h1
2 files changed, 11 insertions, 1 deletions
diff --git a/src/widgets/kernel/qwidget.cpp b/src/widgets/kernel/qwidget.cpp
index 4ca2e996ad..2da967485b 100644
--- a/src/widgets/kernel/qwidget.cpp
+++ b/src/widgets/kernel/qwidget.cpp
@@ -150,6 +150,7 @@ QWidgetPrivate::QWidgetPrivate(int version)
#endif
, directFontResolveMask(0)
, inheritedFontResolveMask(0)
+ , directPaletteResolveMask(0)
, inheritedPaletteResolveMask(0)
, leftmargin(0)
, topmargin(0)
@@ -1845,7 +1846,9 @@ void QWidgetPrivate::propagatePaletteChange()
if (q->isWindow() && !q->testAttribute(Qt::WA_WindowPropagation)) {
inheritedPaletteResolveMask = 0;
}
- int mask = data.pal.resolve() | inheritedPaletteResolveMask;
+
+ directPaletteResolveMask = data.pal.resolve();
+ auto mask = directPaletteResolveMask | inheritedPaletteResolveMask;
const bool useStyleSheetPropagationInWidgetStyles =
QCoreApplication::testAttribute(Qt::AA_UseStyleSheetPropagationInWidgetStyles);
@@ -10452,6 +10455,12 @@ void QWidget::setParent(QWidget *parent, Qt::WindowFlags f)
if (!useStyleSheetPropagationInWidgetStyles && !testAttribute(Qt::WA_StyleSheet)
&& (!parent || !parent->testAttribute(Qt::WA_StyleSheet))) {
+ // if the parent has a font set or inherited, then propagate the mask to the new child
+ if (parent) {
+ const auto pd = parent->d_func();
+ d->inheritedFontResolveMask = pd->directFontResolveMask | pd->inheritedFontResolveMask;
+ d->inheritedPaletteResolveMask = pd->directPaletteResolveMask | pd->inheritedPaletteResolveMask;
+ }
d->resolveFont();
d->resolvePalette();
}
diff --git a/src/widgets/kernel/qwidget_p.h b/src/widgets/kernel/qwidget_p.h
index 6915782cb3..2597017318 100644
--- a/src/widgets/kernel/qwidget_p.h
+++ b/src/widgets/kernel/qwidget_p.h
@@ -672,6 +672,7 @@ public:
// Other variables.
uint directFontResolveMask;
uint inheritedFontResolveMask;
+ decltype(std::declval<QPalette>().resolve()) directPaletteResolveMask;
uint inheritedPaletteResolveMask;
short leftmargin;
short topmargin;