Regarding some task I must do the following. Consider I have a QDoubleSpinBox with positive values from 0 to 1000. And every time when user tries to lower the value of spinbox, f.e. to click the down button when value is 0, the value of spinbox must be string "unset". I tried to do this, to clear the value of spinbox and then setPrefix. But it did not worked. Any other solutions?
Set string to QDoubleSpinBox
3.6k views Asked by Eduard Rostomyan At
3
There are 3 answers
0
On
There are two solutions to achieve what you want.
As pezy in the other answer says using setSpecialValueText where the text is shown when the current value() == minimum() of the spinbox
or a bit more powerful: subclass QSpinBox and override following functions:
int valueFromText(const QString &text) const;
QString textFromValue(int value) const;
QValidator::State validate(QString & input, int & pos) const;
Have a look here, trying something similar QSpinBox enter NaN as a valid value.
You can try
specialValueText
.This is a example:
when value is 0, the value of spinbox must be string "unset".