From 495e5cbbb02a15a8bd7416078295580b2a936477 Mon Sep 17 00:00:00 2001 From: Wladimir Leuschner Date: Wed, 17 Apr 2024 17:17:39 +0200 Subject: [PATCH] QWindows11Style: Increase min size of QAbstractSpinbox Widgets With WinUI3 a new layout of the lineedit and buttons was introduced. The buttons are now aligned horizontally instead of vertically. Trying to mimic that layout in widgets results in too few space for the text in the lineedit. This patch increases the minimum width when using the QWindows11Style for QAbstractSpinBox elements and saves the original width in a property in case the style is changed at runtime to restore the original geometry. Fixes: QTBUG-124235 Fixes: QTBUG-124150 Change-Id: I8067b338fa4a2c1efd0a1b0644fb8a563601385b Reviewed-by: Axel Spoerl (cherry picked from commit b457376c038acc0c1cb9a0966508b4999314ea86) Reviewed-by: Qt Cherry-pick Bot --- .../styles/modernwindows/qwindows11style.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/plugins/styles/modernwindows/qwindows11style.cpp b/src/plugins/styles/modernwindows/qwindows11style.cpp index eaf30b2e0a6..3d07677c5aa 100644 --- a/src/plugins/styles/modernwindows/qwindows11style.cpp +++ b/src/plugins/styles/modernwindows/qwindows11style.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include #include @@ -27,6 +28,7 @@ QT_BEGIN_NAMESPACE const static int topLevelRoundingRadius = 8; //Radius for toplevel items like popups for round corners const static int secondLevelRoundingRadius = 4; //Radius for second level items like hovered menu item round corners +constexpr QLatin1StringView originalWidthProperty("_q_windows11_style_original_width"); enum WINUI3Color { subtleHighlightColor, //Subtle highlight based on alpha used for hovered elements @@ -2046,6 +2048,13 @@ void QWindows11Style::polish(QWidget* widget) QLineEdit *le = cb->lineEdit(); le->setFrame(false); } + } else if (widget->inherits("QAbstractSpinBox")) { + const int minWidth = 2 * 24 + 40; + const int originalWidth = widget->size().width(); + if (originalWidth < minWidth) { + widget->resize(minWidth, widget->size().height()); + widget->setProperty(originalWidthProperty.constData(), originalWidth); + } } else if (widget->inherits("QAbstractButton") || widget->inherits("QToolButton")) { widget->setAutoFillBackground(false); } else if (qobject_cast(widget) && !qobject_cast(widget)) { @@ -2085,6 +2094,13 @@ void QWindows11Style::unpolish(QWidget *widget) scrollarea->viewport()->setPalette(pal); scrollarea->viewport()->setProperty("_q_original_background_palette", QVariant()); } + if (widget->inherits("QAbstractSpinBox")) { + const QVariant originalWidth = widget->property(originalWidthProperty.constData()); + if (originalWidth.isValid()) { + widget->resize(originalWidth.toInt(), widget->size().height()); + widget->setProperty(originalWidthProperty.constData(), QVariant()); + } + } } /*