QStyleSheetStyle: Fix resetting fonts for subwidgets
When a compound widget is styled with a font through a property and the default styling has no font settings, the font was not reset to the parent font but left it the styled state. Fix it by not resolving the current font when the style rule has no font settings - use the parent font directly instead. Fixes: QTBUG-131685 Pick-to: 6.8 Change-Id: I8e79423cfeff24143cd051b282503c4565125b4d Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit 5731fe051e48e7a256ef31ae93cfb89ce8d871cc) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
a8b8a6fd6d
commit
0dd2561d54
@ -6485,9 +6485,9 @@ void QStyleSheetStyle::updateStyleSheetFont(QWidget* w) const
|
|||||||
font.setResolveMask(wf.resolveMask() | rule.font.resolveMask());
|
font.setResolveMask(wf.resolveMask() | rule.font.resolveMask());
|
||||||
|
|
||||||
if ((!w->isWindow() || w->testAttribute(Qt::WA_WindowPropagation))
|
if ((!w->isWindow() || w->testAttribute(Qt::WA_WindowPropagation))
|
||||||
&& isNaturalChild(w) && qobject_cast<QWidget *>(w->parent())) {
|
&& isNaturalChild(w) && w->parentWidget()) {
|
||||||
|
const auto parentFont = w->parentWidget()->font();
|
||||||
font = font.resolve(static_cast<QWidget *>(w->parent())->font());
|
font = rule.hasFont ? font.resolve(parentFont) : parentFont;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (wf.resolveMask() == font.resolveMask() && wf == font)
|
if (wf.resolveMask() == font.resolveMask() && wf == font)
|
||||||
|
@ -125,6 +125,8 @@ private slots:
|
|||||||
void inheritWidgetPalette_data();
|
void inheritWidgetPalette_data();
|
||||||
void inheritWidgetPalette();
|
void inheritWidgetPalette();
|
||||||
|
|
||||||
|
void resetFont();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static QColor COLOR(const QWidget &w)
|
static QColor COLOR(const QWidget &w)
|
||||||
{
|
{
|
||||||
@ -2528,6 +2530,28 @@ void tst_QStyleSheetStyle::inheritWidgetPalette()
|
|||||||
QCOMPARE(phColor, phColorPalette);
|
QCOMPARE(phColor, phColorPalette);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void tst_QStyleSheetStyle::resetFont()
|
||||||
|
{
|
||||||
|
QDoubleSpinBox sb;
|
||||||
|
sb.setStyleSheet(R"(QDoubleSpinBox[changed="true"] {font: italic;})");
|
||||||
|
|
||||||
|
auto checkFont = [&sb](bool isItalic) {
|
||||||
|
sb.setProperty("changed", isItalic);
|
||||||
|
sb.style()->polish(&sb);
|
||||||
|
const auto children = sb.findChildren<QWidget *>();
|
||||||
|
for (const auto *w : children) {
|
||||||
|
auto diagnostics = qScopeGuard([&] {
|
||||||
|
qWarning() << "Failure with" << w << "should be italic:" << isItalic;
|
||||||
|
});
|
||||||
|
QCOMPARE(w->font().italic(), isItalic);
|
||||||
|
diagnostics.dismiss();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
checkFont(false);
|
||||||
|
checkFont(true);
|
||||||
|
checkFont(false);
|
||||||
|
}
|
||||||
|
|
||||||
QTEST_MAIN(tst_QStyleSheetStyle)
|
QTEST_MAIN(tst_QStyleSheetStyle)
|
||||||
#include "tst_qstylesheetstyle.moc"
|
#include "tst_qstylesheetstyle.moc"
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user