From be03e8523df3922d4f8987db8f1ca7293b63f6a2 Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Fri, 2 Feb 2024 16:35:29 +0100 Subject: [PATCH] QFusionStyle: Pass handling of FrameGroupBox to base style The fusion style had an own handling for PE_FrameGroupBox/SC_GroupBoxFrame but failed to handle all cases (e.g. with checkbox, text and horizontal alignment) correct. In contrast, the base class (QCommonStyle) is properly handling all those attributes and returns a correct subControlRect(). Therefore remove the special handling, let styleHint() return the correct value for SH_GroupBox_TextLabelVerticalAlginment based on the groupBox's text alignment and rely on QCommonStyle ability to calculate the correct values. Pick-to: 6.6 Fixes: QTBUG-85425 Fixes: QTBUG-95472 Change-Id: I98ccf861274026a8fd4a2ef436efc3bb009be056 Reviewed-by: Axel Spoerl Reviewed-by: Wladimir Leuschner (cherry picked from commit 5a032f0b3fcfb7dbd63e784dedaa8e27fc34ce3d) Reviewed-by: Qt Cherry-pick Bot --- src/widgets/styles/qcommonstyle.cpp | 2 +- src/widgets/styles/qfusionstyle.cpp | 28 +++++++++++++--------------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/src/widgets/styles/qcommonstyle.cpp b/src/widgets/styles/qcommonstyle.cpp index 4c9605f7069..1ad06b09ed9 100644 --- a/src/widgets/styles/qcommonstyle.cpp +++ b/src/widgets/styles/qcommonstyle.cpp @@ -4384,7 +4384,7 @@ QRect QCommonStyle::subControlRect(ComplexControl cc, const QStyleOptionComplex if (verticalAlignment & Qt::AlignVCenter) topMargin = topHeight / 2; else if (verticalAlignment & Qt::AlignTop) - topMargin = topHeight; + topMargin = topHeight + proxy()->pixelMetric(PM_FocusFrameVMargin, groupBox, widget); } QRect frameRect = groupBox->rect; diff --git a/src/widgets/styles/qfusionstyle.cpp b/src/widgets/styles/qfusionstyle.cpp index 15ea72a1243..4fcdf50c721 100644 --- a/src/widgets/styles/qfusionstyle.cpp +++ b/src/widgets/styles/qfusionstyle.cpp @@ -346,16 +346,7 @@ void QFusionStyle::drawPrimitive(PrimitiveElement elem, case PE_FrameGroupBox: { QPixmap pixmap(":/qt-project.org/styles/commonstyle/images/fusion_groupbox.png"_L1); - int topMargin = 0; - auto control = qobject_cast(widget); - if (control && !control->isCheckable() && control->title().isEmpty()) { - // Shrinking the topMargin if Not checkable AND title is empty - topMargin = groupBoxTopMargin; - } else { - topMargin = qMax(pixelMetric(PM_IndicatorHeight, option, widget), option->fontMetrics.height()) + groupBoxTopMargin; - } - QRect frame = option->rect.adjusted(0, topMargin, 0, 0); - qDrawBorderPixmap(painter, frame, QMargins(6, 6, 6, 6), pixmap); + qDrawBorderPixmap(painter, option->rect, QMargins(6, 6, 6, 6), pixmap); break; } #endif // QT_CONFIG(groupbox) @@ -3331,12 +3322,8 @@ QRect QFusionStyle::subControlRect(ComplexControl control, const QStyleOptionCom const bool hasVerticalAlignment = (groupBoxTextAlignment & Qt::AlignVertical_Mask) == Qt::AlignVCenter; const int fontMetricsHeight = groupBox->text.isEmpty() ? 0 : groupBox->fontMetrics.height(); - rect = option->rect; if (subControl == SC_GroupBoxFrame) - if (hasVerticalAlignment) - return rect.adjusted(0, -(fontMetricsHeight + 4) / 2, 0, 0); - else - return rect; + return rect; else if (subControl == SC_GroupBoxContents) { QRect frameRect = option->rect.adjusted(0, 0, 0, -groupBoxBottomMargin); int margin = 3; @@ -3620,6 +3607,17 @@ int QFusionStyle::styleHint(StyleHint hint, const QStyleOption *option, const QW mask->region -= QRect(option->rect.right() , option->rect.top() + 3, 1, 2); return 1; } + break; + case SH_GroupBox_TextLabelVerticalAlignment: { + if (const auto *groupBox = qstyleoption_cast(option)) { + if (groupBox) { + const auto vAlign = groupBox->textAlignment & Qt::AlignVertical_Mask; + // default fusion style is AlignTop + return vAlign == 0 ? Qt::AlignTop : vAlign; + } + } + break; + } default: break; }