From 41eeb5a273d64aedfb110fee1dd445dd66e927bd Mon Sep 17 00:00:00 2001 From: Alessandro Portale Date: Wed, 3 Apr 2024 19:16:37 +0200 Subject: [PATCH] Core: Fix QGroupBox frame drawing for Qt >= 6.6.3, dark themes Since QStyle::subControlRect() used to return bogus rectangles for SC_GroupBoxFrame, and therefore, as workaround, ManhattanStyle calculated the position of the QGroupBox frame itself via code copied from QFusionStyle. 6.6.3 fixes the SC_GroupBoxFrame issue, but in turn, the old workaround fails. Therefore, this change uses old calculation when running with older Qt and the newer one with Qt >= 6.6.3. Fixes: QTCREATORBUG-30632 Change-Id: Ie9c6c078ba9bd0e7012192e9d887a702e307d294 Reviewed-by: Marcus Tillmanns --- src/plugins/coreplugin/manhattanstyle.cpp | 40 ++++++++++++++++------- 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/src/plugins/coreplugin/manhattanstyle.cpp b/src/plugins/coreplugin/manhattanstyle.cpp index 4aa3c6464d5..37bdbc6ae78 100644 --- a/src/plugins/coreplugin/manhattanstyle.cpp +++ b/src/plugins/coreplugin/manhattanstyle.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -488,21 +489,36 @@ static void drawPrimitiveTweakedForDarkTheme(QStyle::PrimitiveElement element, break; } case QStyle::PE_FrameGroupBox: { - // Snippet from QFusionStyle::drawPrimitive - BEGIN - static const int groupBoxTopMargin = 3; + QRect groupBoxFrame = option->rect; int topMargin = 0; - auto control = dynamic_cast(widget); - if (control && !control->isCheckable() && control->title().isEmpty()) { - // Shrinking the topMargin if Not checkable AND title is empty - topMargin = groupBoxTopMargin; - } else { - const int exclusiveIndicatorHeight = widget ? widget->style()->pixelMetric(QStyle::PM_ExclusiveIndicatorHeight) : 0; - topMargin = qMax(exclusiveIndicatorHeight, - option->fontMetrics.height()) + groupBoxTopMargin; + if (widget) { + // Before Qt 6.6.3, QStyle::subControlRect() returned wrong QRect for SC_GroupBoxFrame + static const bool validSCRect = QLibraryInfo::version() >= QVersionNumber(6, 6, 3); + if (validSCRect) { + QStyleOptionGroupBox opt; + opt.initFrom(widget); + const QStyle *style = widget->style(); + groupBoxFrame = style->subControlRect(QStyle::CC_GroupBox, &opt, + QStyle::SC_GroupBoxFrame, widget); + topMargin = 1; // Tweak to resemble the pre-6.6.3 frame + } else { + // Snippet from pre-6.6.3 FusionStyle::drawPrimitive - BEGIN + static const int groupBoxTopMargin = 3; + auto control = dynamic_cast(widget); + if (!control->isCheckable() && control->title().isEmpty()) { + // Shrinking the topMargin if Not checkable AND title is empty + topMargin = groupBoxTopMargin; + } else { + const int exclusiveIndicatorHeight = + widget->style()->pixelMetric(QStyle::PM_ExclusiveIndicatorHeight); + topMargin = qMax(exclusiveIndicatorHeight, + option->fontMetrics.height()) + groupBoxTopMargin; + } + // Snippet from pre-6.6.3 QFusionStyle::drawPrimitive - END + } } - // Snippet from QFusionStyle::drawPrimitive - END - const QRectF frameRectF = QRectF(option->rect).adjusted(0.5, topMargin + 0.5, -0.5, -0.5); + const QRectF frameRectF = QRectF(groupBoxFrame).adjusted(0.5, topMargin + 0.5, -0.5, -0.5); painter->setPen(framePen); if (isEnabled) painter->setOpacity(0.5);