View Full Version : How to Set Range in qspinbox and add exception value?

16th April 2019, 11:57
Hi Everyone,

I'm working on TCP/UDP communication in which I have set a range for ports as below

QSpinBox *spinBox = new QSpinBox(parent);
spinBox->setRange(1024, 65535);
Now I want to connect to port 80(specific), but because of the above configuration, I'm unable to use port 80.

So my question is, does it possible to add exceptional value/port in spinbox?

16th April 2019, 13:30
Hi, I don't think that's possible. There are a bunch of other options, e.g. use a QComboBox for a bunch of pre-defined ports like your port 80, and the QSpinBox for custom ports >= 1024, and use two QRadiobuttons to switch between both.


16th April 2019, 19:00
If you have a set of special values then a QComboBox like suggested by Ginsengelf could also be extended to have one value for "range" and which enables/shows the spinbox when selected.

If you have one special value, you could use QSpinBox::setSpecialValueText().
It displays a custom text instead of the numerical value for the spinbox' minimum.

You could have possibly multiple special values at the beginning or the end by deriving from QSpinBox and overwrite textFromValue() such that the numbers are not displayed but a special text.