|
| 1 | +QWindows11Style: Calculate Spinbox size based on CommonStyle size |
| 2 | +Use the calculation from Commonstyle and add the increased padding and |
| 3 | +horizontally layouted buttons to the horizontal size hint. |
| 4 | + |
| 5 | +Fixes: QTBUG-130288 |
| 6 | +Change-Id: I7932b782e7873a0178091a51379f17453eb585fd |
| 7 | + |
| 8 | +Upstream commits: |
| 9 | + - Qt 6.8.1: 9107817eaceaacc968dbc767c24594566d637b8c |
| 10 | + - Qt 6.9.0: 96d46cad43517adefa2eb7cb8819a0b2cc9241e6 |
| 11 | + |
| 12 | +--- a/qtbase/src/plugins/styles/modernwindows/qwindows11style.cpp |
| 13 | ++++ b/qtbase/src/plugins/styles/modernwindows/qwindows11style.cpp |
| 14 | +@@ -2048,39 +2048,22 @@ QSize QWindows11Style::sizeFromContents(ContentsType type, const QStyleOption *o |
| 15 | + } |
| 16 | + break; |
| 17 | + #endif |
| 18 | ++#if QT_CONFIG(spinbox) |
| 19 | + case QStyle::CT_SpinBox: { |
| 20 | + if (const auto *spinBoxOpt = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) { |
| 21 | + // Add button + frame widths |
| 22 | +- int width = 0; |
| 23 | +- |
| 24 | +- if (const QDateTimeEdit *spinBox = qobject_cast<const QDateTimeEdit *>(widget)) { |
| 25 | +- const QSize textSizeMin = spinBoxOpt->fontMetrics.size(Qt::TextSingleLine, spinBox->minimumDateTime().toString(spinBox->displayFormat())); |
| 26 | +- const QSize textSizeMax = spinBoxOpt->fontMetrics.size(Qt::TextSingleLine, spinBox->maximumDateTime().toString(spinBox->displayFormat())); |
| 27 | +- width = qMax(textSizeMin.width(),textSizeMax.width()); |
| 28 | +- } else if (const QSpinBox *spinBox = qobject_cast<const QSpinBox *>(widget)) { |
| 29 | +- const QSize textSizeMin = spinBoxOpt->fontMetrics.size(Qt::TextSingleLine, QString::number(spinBox->minimum())); |
| 30 | +- const QSize textSizeMax = spinBoxOpt->fontMetrics.size(Qt::TextSingleLine, QString::number(spinBox->maximum())); |
| 31 | +- width = qMax(textSizeMin.width(),textSizeMax.width()); |
| 32 | +- width += spinBoxOpt->fontMetrics.size(Qt::TextSingleLine, spinBox->prefix()).width(); |
| 33 | +- width += spinBoxOpt->fontMetrics.size(Qt::TextSingleLine, spinBox->suffix()).width(); |
| 34 | +- |
| 35 | +- } else if (const QDoubleSpinBox *spinBox = qobject_cast<const QDoubleSpinBox *>(widget)) { |
| 36 | +- const QSize textSizeMin = spinBoxOpt->fontMetrics.size(Qt::TextSingleLine, QString::number(spinBox->minimum())); |
| 37 | +- const QSize textSizeMax = spinBoxOpt->fontMetrics.size(Qt::TextSingleLine, QString::number(spinBox->maximum())); |
| 38 | +- width = qMax(textSizeMin.width(),textSizeMax.width()); |
| 39 | +- width += spinBoxOpt->fontMetrics.size(Qt::TextSingleLine, spinBox->prefix()).width(); |
| 40 | +- width += spinBoxOpt->fontMetrics.size(Qt::TextSingleLine, spinBox->suffix()).width(); |
| 41 | +- } |
| 42 | + const qreal dpi = QStyleHelper::dpi(option); |
| 43 | + const bool hasButtons = (spinBoxOpt->buttonSymbols != QAbstractSpinBox::NoButtons); |
| 44 | +- const int buttonWidth = hasButtons ? 2 * qRound(QStyleHelper::dpiScaled(16, dpi)) : 0; |
| 45 | ++ const int margins = 8; |
| 46 | ++ const int buttonWidth = hasButtons ? qRound(QStyleHelper::dpiScaled(16, dpi)) : 0; |
| 47 | + const int frameWidth = spinBoxOpt->frame ? proxy()->pixelMetric(PM_SpinBoxFrameWidth, |
| 48 | + spinBoxOpt, widget) : 0; |
| 49 | +- contentSize.setWidth(2 * 12 + width); |
| 50 | +- contentSize += QSize(buttonWidth + 2 * frameWidth, 2 * frameWidth); |
| 51 | ++ |
| 52 | ++ contentSize += QSize(2 * buttonWidth + 2 * frameWidth + 2 * margins, 2 * frameWidth); |
| 53 | + } |
| 54 | + break; |
| 55 | + } |
| 56 | ++#endif |
| 57 | + default: |
| 58 | + contentSize = QWindowsVistaStyle::sizeFromContents(type, option, size, widget); |
| 59 | + break; |
| 60 | + |
| 61 | + |
| 62 | +Windows11Style: don't set minimum width for QAbstractSpinBox |
| 63 | + |
| 64 | +There is no need to set a minimum width for QAbstractSpinBox in |
| 65 | +QWindows11Style::polish() as this might override the user preferences. |
| 66 | +Also the minimum size handling is now properly done within |
| 67 | +sizeFromContents(). |
| 68 | + |
| 69 | +Change-Id: Ibc1fd7a6f862fc85e3739025b9de581aa235d74c |
| 70 | + |
| 71 | +Upstream commits: |
| 72 | + - Qt 6.8.3: f86da3d3f853adb1a5b823c1cc7be6db4a0265f3 |
| 73 | + - Qt 6.9.0: b93a8dfdfe6900cb542fdc587dd2682007a6ac53 |
| 74 | + - Qt 6.10.0: 2ec4c28470de115c16944653a5d4f6209452d56c |
| 75 | + |
| 76 | +--- a/qtbase/src/plugins/styles/modernwindows/qwindows11style.cpp |
| 77 | ++++ b/qtbase/src/plugins/styles/modernwindows/qwindows11style.cpp |
| 78 | +@@ -29,7 +29,6 @@ QT_BEGIN_NAMESPACE |
| 79 | + |
| 80 | + const static int topLevelRoundingRadius = 8; //Radius for toplevel items like popups for round corners |
| 81 | + const static int secondLevelRoundingRadius = 4; //Radius for second level items like hovered menu item round corners |
| 82 | +-constexpr QLatin1StringView originalWidthProperty("_q_windows11_style_original_width"); |
| 83 | + |
| 84 | + enum WINUI3Color { |
| 85 | + subtleHighlightColor, //Subtle highlight based on alpha used for hovered elements |
| 86 | +@@ -2140,13 +2139,6 @@ void QWindows11Style::polish(QWidget* widget) |
| 87 | + pal.setColor(QPalette::ButtonText, pal.text().color()); |
| 88 | + pal.setColor(QPalette::BrightText, pal.text().color()); |
| 89 | + widget->setPalette(pal); |
| 90 | +- } else if (widget->inherits("QAbstractSpinBox")) { |
| 91 | +- const int minWidth = 2 * 24 + 40; |
| 92 | +- const int originalWidth = widget->size().width(); |
| 93 | +- if (originalWidth < minWidth) { |
| 94 | +- widget->resize(minWidth, widget->size().height()); |
| 95 | +- widget->setProperty(originalWidthProperty.constData(), originalWidth); |
| 96 | +- } |
| 97 | + } else if (widget->inherits("QAbstractButton") || widget->inherits("QToolButton")) { |
| 98 | + widget->setAutoFillBackground(false); |
| 99 | + auto pal = widget->palette(); |
| 100 | +@@ -2191,13 +2183,6 @@ void QWindows11Style::unpolish(QWidget *widget) |
| 101 | + scrollarea->viewport()->setPalette(pal); |
| 102 | + scrollarea->viewport()->setProperty("_q_original_background_palette", QVariant()); |
| 103 | + } |
| 104 | +- if (widget->inherits("QAbstractSpinBox")) { |
| 105 | +- const QVariant originalWidth = widget->property(originalWidthProperty.constData()); |
| 106 | +- if (originalWidth.isValid()) { |
| 107 | +- widget->resize(originalWidth.toInt(), widget->size().height()); |
| 108 | +- widget->setProperty(originalWidthProperty.constData(), QVariant()); |
| 109 | +- } |
| 110 | +- } |
| 111 | + } |
| 112 | + |
| 113 | + /* |
0 commit comments