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 <axel.spoerl@qt.io>
Reviewed-by: Wladimir Leuschner <wladimir.leuschner@qt.io>
(cherry picked from commit 5a032f0b3fcfb7dbd63e784dedaa8e27fc34ce3d)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Christian Ehrlicher 2024-02-02 16:35:29 +01:00 committed by Qt Cherry-pick Bot
parent 9ce4f8ad82
commit be03e8523d
2 changed files with 14 additions and 16 deletions

View File

@ -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;

View File

@ -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<const QGroupBox *>(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<const QStyleOptionGroupBox *>(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;
}