From 74e0ed217fdec8e32227f9f845eccac7f1552297 Mon Sep 17 00:00:00 2001 From: Volker Hilsheimer Date: Wed, 10 Apr 2024 15:25:59 +0200 Subject: StyleSheet: respect a font weight set for header sections QCommonStyle sets the font for a selected header section to bold. This overrides the font weight a calling style might already have set, e.g. when a style sheet is applied to explicitly set a weight for a checked header section: QHeaderView::section:checked { font-size: 20px font-weight: normal } Since setting the weight on a font sets the respective resolve-mask bit, we can avoid overwriting a weight that is already set explicitly. Add baseline test coverage using a QTableWidget. Fixes: QTBUG-122180 Pick-to: 6.7 6.5 Change-Id: I8c6279ad2fd8c5718ebea26e27c64ae823625748 Reviewed-by: Axel Spoerl --- src/widgets/styles/qcommonstyle.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'src/widgets') diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index 07682d0ae0..1ab9886796 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -1679,9 +1679,12 @@ void QCommonStyle::drawControl(ControlElement element, const QStyleOption *opt, QFontMetrics fm(header->fontMetrics); if (header->state & QStyle::State_On) { QFont fnt = p->font(); - fnt.setBold(true); - p->setFont(fnt); - fm = QFontMetrics((p->font())); + // the font already has a weight set; don't override that + if (!(fnt.resolveMask() & QFont::WeightResolved)) { + fnt.setBold(true); + p->setFont(fnt); + fm = QFontMetrics((p->font())); + } } QString text = header->text; if (const QStyleOptionHeaderV2 *headerV2 = qstyleoption_cast(header)) { -- cgit v1.2.3