QWindows11Style: Increase QSpinBox width for layouted QSpinboxes
QSpinboxes used the sizeFromContents from QWindowsVistaStyle, which produced a too small contentRect for the newly horizontal layouted buttons on QSpinBox. This patch sets a minimum width for the content rect, when QWindows11Style is used. Fixes: QTBUG-124118 Pick-to: 6.7 Change-Id: Ibf58c8da360242587e55f8096fa3157459041ba6 Reviewed-by: Oliver Wolff <oliver.wolff@qt.io> (cherry picked from commit bfe8ac4ebff7a1e8114068f2f46e73c588735690) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
d2e9a03ee3
commit
b3a25e845a
@ -20,6 +20,7 @@
|
|||||||
#endif
|
#endif
|
||||||
#include <QtWidgets/qtextedit.h>
|
#include <QtWidgets/qtextedit.h>
|
||||||
#include <QtWidgets/qtreeview.h>
|
#include <QtWidgets/qtreeview.h>
|
||||||
|
#include <QtWidgets/qdatetimeedit.h>
|
||||||
|
|
||||||
#include "qdrawutil.h"
|
#include "qdrawutil.h"
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
@ -272,7 +273,6 @@ void QWindows11Style::drawComplexControl(ComplexControl control, const QStyleOpt
|
|||||||
}
|
}
|
||||||
if (sub & SC_SpinBoxUp) {
|
if (sub & SC_SpinBoxUp) {
|
||||||
QRect rect = proxy()->subControlRect(CC_SpinBox, option, SC_SpinBoxUp, widget).adjusted(0, 0, 0, 1);
|
QRect rect = proxy()->subControlRect(CC_SpinBox, option, SC_SpinBoxUp, widget).adjusted(0, 0, 0, 1);
|
||||||
float scale = rect.width() >= 16 ? 1.0 : rect.width()/16.0;
|
|
||||||
if (rect.contains(mousePos)) {
|
if (rect.contains(mousePos)) {
|
||||||
painter->setPen(Qt::NoPen);
|
painter->setPen(Qt::NoPen);
|
||||||
painter->setBrush(QBrush(hoverColor));
|
painter->setBrush(QBrush(hoverColor));
|
||||||
@ -280,7 +280,6 @@ void QWindows11Style::drawComplexControl(ComplexControl control, const QStyleOpt
|
|||||||
}
|
}
|
||||||
painter->save();
|
painter->save();
|
||||||
painter->translate(rect.center());
|
painter->translate(rect.center());
|
||||||
painter->scale(scale,scale);
|
|
||||||
painter->translate(-rect.center());
|
painter->translate(-rect.center());
|
||||||
painter->setFont(assetFont);
|
painter->setFont(assetFont);
|
||||||
painter->setPen(sb->palette.buttonText().color());
|
painter->setPen(sb->palette.buttonText().color());
|
||||||
@ -290,7 +289,6 @@ void QWindows11Style::drawComplexControl(ComplexControl control, const QStyleOpt
|
|||||||
}
|
}
|
||||||
if (sub & SC_SpinBoxDown) {
|
if (sub & SC_SpinBoxDown) {
|
||||||
QRect rect = proxy()->subControlRect(CC_SpinBox, option, SC_SpinBoxDown, widget);
|
QRect rect = proxy()->subControlRect(CC_SpinBox, option, SC_SpinBoxDown, widget);
|
||||||
float scale = rect.width() >= 16 ? 1.0 : rect.width()/16.0;
|
|
||||||
if (rect.contains(mousePos)) {
|
if (rect.contains(mousePos)) {
|
||||||
painter->setPen(Qt::NoPen);
|
painter->setPen(Qt::NoPen);
|
||||||
painter->setBrush(QBrush(hoverColor));
|
painter->setBrush(QBrush(hoverColor));
|
||||||
@ -298,7 +296,6 @@ void QWindows11Style::drawComplexControl(ComplexControl control, const QStyleOpt
|
|||||||
}
|
}
|
||||||
painter->save();
|
painter->save();
|
||||||
painter->translate(rect.center());
|
painter->translate(rect.center());
|
||||||
painter->scale(scale,scale);
|
|
||||||
painter->translate(-rect.center());
|
painter->translate(-rect.center());
|
||||||
painter->setFont(assetFont);
|
painter->setFont(assetFont);
|
||||||
painter->setPen(sb->palette.buttonText().color());
|
painter->setPen(sb->palette.buttonText().color());
|
||||||
@ -1871,7 +1868,7 @@ QRect QWindows11Style::subControlRect(ComplexControl control, const QStyleOption
|
|||||||
QSize bs;
|
QSize bs;
|
||||||
int fw = spinbox->frame ? proxy()->pixelMetric(PM_SpinBoxFrameWidth, spinbox, widget) : 0;
|
int fw = spinbox->frame ? proxy()->pixelMetric(PM_SpinBoxFrameWidth, spinbox, widget) : 0;
|
||||||
bs.setHeight(qMax(8, spinbox->rect.height() - fw));
|
bs.setHeight(qMax(8, spinbox->rect.height() - fw));
|
||||||
bs.setWidth(qMin(24.0, spinbox->rect.width()*(1.0/4.0)));
|
bs.setWidth(16);
|
||||||
int y = fw + spinbox->rect.y();
|
int y = fw + spinbox->rect.y();
|
||||||
int x, lx, rx;
|
int x, lx, rx;
|
||||||
x = spinbox->rect.x() + spinbox->rect.width() - fw - 2 * bs.width();
|
x = spinbox->rect.x() + spinbox->rect.width() - fw - 2 * bs.width();
|
||||||
@ -2051,7 +2048,37 @@ QSize QWindows11Style::sizeFromContents(ContentsType type, const QStyleOption *o
|
|||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
case QStyle::CT_SpinBox: {
|
||||||
|
if (const auto *spinBoxOpt = qstyleoption_cast<const QStyleOptionSpinBox *>(option)) {
|
||||||
|
if (qobject_cast<const QDateTimeEdit *>(widget))
|
||||||
|
break;
|
||||||
|
|
||||||
|
// Add button + frame widths
|
||||||
|
int width = 0;
|
||||||
|
if (const QSpinBox *spinBox = qobject_cast<const QSpinBox *>(widget)) {
|
||||||
|
const QSize textSizeMin = spinBoxOpt->fontMetrics.size(Qt::TextSingleLine, QString::number(spinBox->minimum()));
|
||||||
|
const QSize textSizeMax = spinBoxOpt->fontMetrics.size(Qt::TextSingleLine, QString::number(spinBox->maximum()));
|
||||||
|
width = qMax(textSizeMin.width(),textSizeMax.width());
|
||||||
|
width += spinBoxOpt->fontMetrics.size(Qt::TextSingleLine, spinBox->prefix()).width();
|
||||||
|
width += spinBoxOpt->fontMetrics.size(Qt::TextSingleLine, spinBox->suffix()).width();
|
||||||
|
|
||||||
|
} else if (const QDoubleSpinBox *spinBox = qobject_cast<const QDoubleSpinBox *>(widget)) {
|
||||||
|
const QSize textSizeMin = spinBoxOpt->fontMetrics.size(Qt::TextSingleLine, QString::number(spinBox->minimum()));
|
||||||
|
const QSize textSizeMax = spinBoxOpt->fontMetrics.size(Qt::TextSingleLine, QString::number(spinBox->maximum()));
|
||||||
|
width = qMax(textSizeMin.width(),textSizeMax.width());
|
||||||
|
width += spinBoxOpt->fontMetrics.size(Qt::TextSingleLine, spinBox->prefix()).width();
|
||||||
|
width += spinBoxOpt->fontMetrics.size(Qt::TextSingleLine, spinBox->suffix()).width();
|
||||||
|
}
|
||||||
|
const qreal dpi = QStyleHelper::dpi(option);
|
||||||
|
const bool hasButtons = (spinBoxOpt->buttonSymbols != QAbstractSpinBox::NoButtons);
|
||||||
|
const int buttonWidth = hasButtons ? 2 * qRound(QStyleHelper::dpiScaled(16, dpi)) : 0;
|
||||||
|
const int frameWidth = spinBoxOpt->frame ? proxy()->pixelMetric(PM_SpinBoxFrameWidth,
|
||||||
|
spinBoxOpt, widget) : 0;
|
||||||
|
contentSize.setWidth(2 * 12 + width);
|
||||||
|
contentSize += QSize(buttonWidth + 2 * frameWidth, 2 * frameWidth);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
contentSize = QWindowsVistaStyle::sizeFromContents(type, option, size, widget);
|
contentSize = QWindowsVistaStyle::sizeFromContents(type, option, size, widget);
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user