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 <wladimir.leuschner@qt.io>
(cherry picked from commit 696f9adaa4b7a293ff1bfe3fa47dca62b4fdc710)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Christian Ehrlicher 2025-04-07 12:48:33 +02:00 committed by Qt Cherry-pick Bot
parent f7ad71f39c
commit c46fdbad79

View File

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