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 <axel.spoerl@qt.io> (cherry picked from commit b457376c038acc0c1cb9a0966508b4999314ea86) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
3750611d6d
commit
495e5cbbb0
@ -9,6 +9,7 @@
|
||||
#include <qstyleoption.h>
|
||||
#include <qpainter.h>
|
||||
#include <QGraphicsDropShadowEffect>
|
||||
#include <QLatin1StringView>
|
||||
#include <QtWidgets/qcombobox.h>
|
||||
#include <QtWidgets/qcommandlinkbutton.h>
|
||||
#include <QtWidgets/qgraphicsview.h>
|
||||
@ -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<QGraphicsView *>(widget) && !qobject_cast<QTextEdit *>(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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
Loading…
x
Reference in New Issue
Block a user