Reputation: 2423
Nothing I've tried seems to work. setMinimumSize does exactly what I want it to if I switch from a QDoubleSpinBox to a QSpinBox, which leads me to believe this might be a bug in Qt 5.1.
Upvotes: 5
Views: 5897
Reputation: 21594
Actually, QDoubleSpinBox
and QSpinBox
size policy is the same. But note that their minimum width (or width hint) depends on their min/max value. A default QDoubleSpinBox
width is very close to QSpinBox
one, however, if you QDoubleSpinBox
precision is 10 digits and it's max value is set to FLT_MAX
, then it's width will become huge as Qt will set it so that the max value will fit without the widegt size being changed.
To fix that, I found two workarounds:
simply call setSizePolicy( QSizePolicy( QSizePolicy::Ignored, sizePolicy().verticalPolicy() ) );
on the QDoubleSpinBox
.
However, now the layout management may make it become so small that it's content is not visible anymore. So this solution is not perfect.
once the QDoubleSpinBox
is added to a QLayout
, update the layout (call layout->update()
) and then do spinBox->setMinimumWidth( spinBox->minimumSizeHint().width()/2 );
. Now the QDoubleSpinBox
may be twice smaller than before. However, large numbers may not be fully visible.
Upvotes: 1
Reputation: 175
my Qt5.1 looks fine when changing the spinbox size. in the layout? did you set layout settings:
setSizePolicy(QSizePolicy::Ignored,QSizePolicy::Ignored); ?
Upvotes: 3