Fix QSpinbox default width
After aa8d3f90a4
the default width of the
spinbox buttons is calculated from the spinbox width. This is wrong
because the initial width (e.g. when the spinbox is not yet shown) is
640 pixels which results in a too long width.
Therefore fall back to the old hard-coded value version but instead
using 20 pixels, use 16 to be in sync with the stylesheet style value
and honor the dpi of the screen by using QStyleHelper::dpiScaled().
Fixes: QTBUG-79806
Fixes: QTBUG-80814
Change-Id: I45786684575273f940e498df3b7639e626f00a7e
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
This commit is contained in:
parent
f2d752c59f
commit
2614347ab8
@ -5027,8 +5027,9 @@ QSize QCommonStyle::sizeFromContents(ContentsType ct, const QStyleOption *opt,
|
||||
case CT_SpinBox:
|
||||
if (const QStyleOptionSpinBox *vopt = qstyleoption_cast<const QStyleOptionSpinBox *>(opt)) {
|
||||
// Add button + frame widths
|
||||
const qreal dpi = QStyleHelper::dpi(opt);
|
||||
const bool hasButtons = (vopt->buttonSymbols != QAbstractSpinBox::NoButtons);
|
||||
const int buttonWidth = hasButtons ? proxy()->subControlRect(CC_SpinBox, vopt, SC_SpinBoxUp, widget).width() : 0;
|
||||
const int buttonWidth = hasButtons ? qRound(QStyleHelper::dpiScaled(16, dpi)) : 0;
|
||||
const int fw = vopt->frame ? proxy()->pixelMetric(PM_SpinBoxFrameWidth, vopt, widget) : 0;
|
||||
sz += QSize(buttonWidth + 2*fw, 2*fw);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user