summaryrefslogtreecommitdiffstats
path: root/src/widgets/styles
diff options
context:
space:
mode:
authorThorbjørn Lund Martsum <tmartsum@gmail.com>2019-08-16 08:24:22 +0200
committerThorbjørn Lund Martsum <tmartsum@gmail.com>2019-09-18 08:47:46 +0200
commit57e8fe86bdd3a38e8b968f553a3cfaa6541feee1 (patch)
treeb7bddf3cfbda9a790c6204a4430a24e79aea75c9 /src/widgets/styles
parent3278eae5773f21f6b1cc059fa392609e28caa902 (diff)
QStyleSheet: Resolve the rule font before it is used
The styleSheet font cannot know about e.g dpi or other settings (e.g from the current screen) so we should resolve font settings from the original font. This patch ensures that the stylesheet font is resolved with a relevant font before it is used. This likely fixes many dual/triple screen issues. [ChangeLog][QtWidgets][QStyle] Style sheets now only use the part of the stylesheet font that it knows about. The remaining will be resolved/inherited from the context. Fixes: QTBUG-77502 Change-Id: I3b1f821e1be9707506a6c1d1e93f76eeac4007e0 Reviewed-by: Morten Kristensen <me@mortens.dev> Reviewed-by: David Faure <david.faure@kdab.com> Reviewed-by: Christian Ehrlicher <ch.ehrlicher@gmx.de> Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io> (cherry picked from commit b68ade8282274c2d4ee1e4f861d34ea0655c1eab) Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'src/widgets/styles')
-rw-r--r--src/widgets/styles/qstylesheetstyle.cpp20
1 files changed, 12 insertions, 8 deletions
diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp
index dd225fbec3..48d2e268b8 100644
--- a/src/widgets/styles/qstylesheetstyle.cpp
+++ b/src/widgets/styles/qstylesheetstyle.cpp
@@ -615,7 +615,7 @@ public:
public:
int features;
QBrush defaultBackground;
- QFont font;
+ QFont font; // Be careful using this font directly. Prefer using font.resolve( )
bool hasFont;
QHash<QString, QVariant> styleHints;
@@ -3211,7 +3211,7 @@ void QStyleSheetStyle::drawComplexControl(ComplexControl cc, const QStyleOptionC
rule.drawRule(p, opt->rect);
toolOpt.rect = rule.contentsRect(opt->rect);
if (rule.hasFont)
- toolOpt.font = rule.font;
+ toolOpt.font = rule.font.resolve(toolOpt.font);
drawControl(CE_ToolButtonLabel, &toolOpt, p, w);
}
@@ -3514,7 +3514,7 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q
const QFont oldFont = p->font();
if (rule.hasFont)
- p->setFont(rule.font);
+ p->setFont(rule.font.resolve(p->font()));
if (rule.hasPosition() && rule.position()->textAlignment != 0) {
Qt::Alignment textAlignment = rule.position()->textAlignment;
@@ -3678,7 +3678,7 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q
subRule.configurePalette(&mi.palette, QPalette::HighlightedText, QPalette::Highlight);
QFont oldFont = p->font();
if (subRule.hasFont)
- p->setFont(subRule.font.resolve(p->font()));
+ p->setFont(subRule.font.resolve(mi.font));
else
p->setFont(mi.font);
@@ -4084,7 +4084,7 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q
subRule.configurePalette(&boxCopy.palette, QPalette::ButtonText, QPalette::Button);
QFont oldFont = p->font();
if (subRule.hasFont)
- p->setFont(subRule.font);
+ p->setFont(subRule.font.resolve(p->font()));
boxCopy.rect = subRule.contentsRect(opt->rect);
if (subRule.hasImage()) {
// the image is already drawn with CE_ToolBoxTabShape, adjust rect here
@@ -4171,7 +4171,7 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q
subRule.configurePalette(&tabCopy.palette, QPalette::WindowText, QPalette::Base);
QFont oldFont = p->font();
if (subRule.hasFont)
- p->setFont(subRule.font);
+ p->setFont(subRule.font.resolve(p->font()));
if (subRule.hasBox() || !subRule.hasNativeBorder()) {
tabCopy.rect = ce == CE_TabBarTabShape ? subRule.borderRect(r)
: subRule.contentsRect(r);
@@ -5035,8 +5035,12 @@ QSize QStyleSheetStyle::sizeFromContents(ContentsType ct, const QStyleOption *op
bool nullIcon = hdr->icon.isNull();
const int margin = pixelMetric(QStyle::PM_HeaderMargin, hdr, w);
int iconSize = nullIcon ? 0 : pixelMetric(QStyle::PM_SmallIconSize, hdr, w);
- const QSize txt = subRule.hasFont ? QFontMetrics(subRule.font).size(0, hdr->text)
- : hdr->fontMetrics.size(0, hdr->text);
+ QFontMetrics fm = hdr->fontMetrics;
+ if (subRule.hasFont) {
+ QFont styleFont = w ? subRule.font.resolve(w->font()) : subRule.font;
+ fm = QFontMetrics(styleFont);
+ }
+ const QSize txt = fm.size(0, hdr->text);
nativeContentsSize.setHeight(margin + qMax(iconSize, txt.height()) + margin);
nativeContentsSize.setWidth((nullIcon ? 0 : margin) + iconSize
+ (hdr->text.isNull() ? 0 : margin) + txt.width() + margin);