From c46fdbad79f745c5b0d381f8f418bf34ebefcf0c Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Mon, 7 Apr 2025 12:48:33 +0200 Subject: [PATCH] Windows11Style: Fix size hint for RadioButton/Checkbox When the radiobutton/checkbox has no text, the size is to small as the check rect is enlarged by 2px due to the rounded borders. This is only visible when they have no text as otherwise there is enough space between the checkbox and the text. Therefore add 2px in width when no text is available. Pick-to: 6.8 Fixes: QTBUG-135628 Task-number: QTBUG-133117 Change-Id: I8e3342fdc980485ab1494ef7f6df044f42883619 Reviewed-by: Wladimir Leuschner (cherry picked from commit 696f9adaa4b7a293ff1bfe3fa47dca62b4fdc710) Reviewed-by: Qt Cherry-pick Bot --- src/plugins/styles/modernwindows/qwindows11style.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/plugins/styles/modernwindows/qwindows11style.cpp b/src/plugins/styles/modernwindows/qwindows11style.cpp index e42a12218f5..f84a2e06fdb 100644 --- a/src/plugins/styles/modernwindows/qwindows11style.cpp +++ b/src/plugins/styles/modernwindows/qwindows11style.cpp @@ -2147,6 +2147,14 @@ QSize QWindows11Style::sizeFromContents(ContentsType type, const QStyleOption *o // side) so call QWindowsStyle::styleHint directly to get the correct size hint contentSize = QWindowsStyle::sizeFromContents(type, option, size, widget); break; + case CT_RadioButton: + case CT_CheckBox: + // the indicator needs 2px more in width when there is no text, not needed when + // the style draws the text + contentSize = QWindowsVistaStyle::sizeFromContents(type, option, size, widget); + if (size.width() == 0) + contentSize.rwidth() += 2; + break; default: contentSize = QWindowsVistaStyle::sizeFromContents(type, option, size, widget); break;