From 8ffd1adfeff7508a36249c1c31f165af5975086c Mon Sep 17 00:00:00 2001 From: Wladimir Leuschner Date: Tue, 5 Mar 2024 16:47:54 +0100 Subject: [PATCH] QWindows11Style: HighDPI aware qDrawPlainRoundedRect Change-Id: Ic9562a20bce59c265c539a1378f5f8fd8e9e9a17 Reviewed-by: Alessandro Portale (cherry picked from commit df24438e6a2adb344d78628e7a79432f88fab5e9) Reviewed-by: Qt Cherry-pick Bot --- .../styles/modernwindows/qwindows11style.cpp | 18 ++++++++++++------ src/widgets/styles/qdrawutil.cpp | 7 +++++-- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/plugins/styles/modernwindows/qwindows11style.cpp b/src/plugins/styles/modernwindows/qwindows11style.cpp index 27e2ecff6e1..5bc714dfa27 100644 --- a/src/plugins/styles/modernwindows/qwindows11style.cpp +++ b/src/plugins/styles/modernwindows/qwindows11style.cpp @@ -736,19 +736,19 @@ void QWindows11Style::drawPrimitive(PrimitiveElement element, const QStyleOption painter->setPen(highContrastTheme == true ? option->palette.buttonText().color() : WINUI3Colors[colorSchemeIndex][frameColorLight]); painter->setBrush(Qt::NoBrush); - painter->drawRoundedRect(tipRect.marginsAdded(QMargins(0.5,0.5,0.5,0.5)), secondLevelRoundingRadius, secondLevelRoundingRadius); + painter->drawRoundedRect(tipRect.marginsAdded(QMarginsF(0.5,0.5,0.5,0.5)), secondLevelRoundingRadius, secondLevelRoundingRadius); break; } case PE_FrameTabWidget: if (const QStyleOptionTabWidgetFrame *frame = qstyleoption_cast(option)) { - QRectF frameRect = frame->rect.marginsRemoved(QMargins(1,1,1,1)); + QRectF frameRect = frame->rect.marginsRemoved(QMargins(0,0,0,0)); painter->setPen(Qt::NoPen); painter->setBrush(frame->palette.base()); painter->drawRoundedRect(frameRect, secondLevelRoundingRadius, secondLevelRoundingRadius); painter->setPen(highContrastTheme == true ? frame->palette.buttonText().color() : WINUI3Colors[colorSchemeIndex][frameColorLight]); painter->setBrush(Qt::NoBrush); - painter->drawRoundedRect(frameRect.marginsAdded(QMargins(0.5,0.5,0.5,0.5)), secondLevelRoundingRadius, secondLevelRoundingRadius); + painter->drawRoundedRect(frameRect.marginsRemoved(QMarginsF(0.5,0.5,0.5,0.5)), secondLevelRoundingRadius, secondLevelRoundingRadius); } break; case PE_FrameGroupBox: @@ -855,8 +855,14 @@ void QWindows11Style::drawPrimitive(PrimitiveElement element, const QStyleOption } break; case PE_PanelButtonBevel:{ - QRect rect = option->rect.marginsRemoved(QMargins(2,2,2,2)); + QRectF rect = option->rect.marginsRemoved(QMargins(2,2,2,2)); + rect.adjust(-0.5,-0.5,0.5,0.5); + painter->setBrush(Qt::NoBrush); painter->setPen(QPen(WINUI3Colors[colorSchemeIndex][controlStrokePrimary])); + painter->drawRoundedRect(rect, secondLevelRoundingRadius, secondLevelRoundingRadius); + + rect = option->rect.marginsRemoved(QMargins(2,2,2,2)); + painter->setPen(Qt::NoPen); if (!(state & (State_Raised))) painter->setBrush(WINUI3Colors[colorSchemeIndex][controlFillTertiary]); else if (state & State_MouseOver) @@ -917,7 +923,7 @@ void QWindows11Style::drawPrimitive(PrimitiveElement element, const QStyleOption if (const auto *frame = qstyleoption_cast(option)) { if (frame->frameShape == QFrame::NoFrame) break; - QRectF rect = option->rect.adjusted(2,2,-2,-2); + QRectF rect = option->rect.adjusted(1,1,-1,-1); if (widget && widget->inherits("QComboBoxPrivateContainer")) { painter->setPen(Qt::NoPen); painter->setBrush(WINUI3Colors[colorSchemeIndex][menuPanelFill]); @@ -930,7 +936,7 @@ void QWindows11Style::drawPrimitive(PrimitiveElement element, const QStyleOption painter->setBrush(Qt::NoBrush); painter->setPen(QPen(WINUI3Colors[colorSchemeIndex][frameColorLight])); - painter->drawRoundedRect(rect.marginsAdded(QMargins(0.5,0.5,0.5,0.5)), secondLevelRoundingRadius, secondLevelRoundingRadius); + painter->drawRoundedRect(rect.marginsRemoved(QMarginsF(0.5,0.5,0.5,0.5)), secondLevelRoundingRadius, secondLevelRoundingRadius); if (widget && widget->inherits("QTextEdit")) { QRegion clipRegion = option->rect; diff --git a/src/widgets/styles/qdrawutil.cpp b/src/widgets/styles/qdrawutil.cpp index 41b4886f2f9..5bdbdb11395 100644 --- a/src/widgets/styles/qdrawutil.cpp +++ b/src/widgets/styles/qdrawutil.cpp @@ -664,8 +664,11 @@ void qDrawPlainRoundedRect(QPainter *p, int x, int y, int w, int h, p->save(); p->setPen(c); p->setBrush(Qt::NoBrush); - for (int i=0; idrawRoundedRect(x+i, y+i, w-i*2 - 1, h-i*2 - 1, rx, ry); + for (int i=0; idrawRoundedRect(rect, rx, ry); + } if (fill) { // fill with fill color p->setPen(Qt::NoPen); p->setBrush(*fill);