forked from qt-creator/qt-creator
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 <marcus.tillmanns@qt.io>
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
#include <QFormLayout>
|
||||
#include <QGroupBox>
|
||||
#include <QLabel>
|
||||
#include <QLibraryInfo>
|
||||
#include <QLineEdit>
|
||||
#include <QMenuBar>
|
||||
#include <QPainter>
|
||||
@@ -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<const QGroupBox *>(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<const QGroupBox *>(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);
|
||||
|
Reference in New Issue
Block a user