PDA

View Full Version : QSpinbox



Markus_AC
7th September 2011, 08:51
Hi all.

I need a Spinbox with 15 possible items. At the beginning the spinbox should have no item and is disabled. Then I scan for devices. As I find one device, I want to add this to the spinbox. This device can have number 1 .. 15. When I find another device with another number, I want to add this device to the spinbox.
Furthermore I do not want to display only the number but additionally the devicename.

Can I do this with QSpinBox? I have to use QT4.5.

schmimona
7th September 2011, 09:00
I don't know about the Spin box but I would use the combo box in your case.

Markus_AC
7th September 2011, 09:09
I know it could be done with a Combobox, but it should be the Spinbox style.
If QSpinbox can't do this, I have to create a widget unsing 1 QTextEdit and 2 QPushButtons and have to manage the slot of the buttons myself. But I hoped a QSpinBox can do this for me.

wysota
7th September 2011, 18:02
You need to create your own spinbox subclass and implement textFromValue() and valueFromText() to convert numbers to whatever you want the textual representation of those numbers to be.

Markus_AC
20th October 2011, 10:01
It's still the same Spinbox, but another problem:

In my Subclass "MySpinBox" derived from QSpinBox I want to enable / disable the up- and down-buttons on my QSpinBox dynamically.
So there is the getter

StepEnabled QAbstractSpinBox::stepEnabled () const [virtual protected]
end the enum


enum QAbstractSpinBox::StepEnabledFlag

QAbstractSpinBox::StepNone 0x00
QAbstractSpinBox::StepUpEnabled 0x01
QAbstractSpinBox::StepDownEnabled 0x02

But where is the setter? I just don't get it.
Please help.

wysota
20th October 2011, 10:13
There is no setter. stepEnabled() is a virtual method which you override and return the current state of buttons. If you want an external setter, implement one in your subclass and reimplement stepEnabled() to take the calls to this setter into account. You'll need a tri-state check -- enabled, disabled explicitly by the setter, disabled implicitly by the value of the spinbox (and the hidden state of disabled by both mechanisms at once).

Markus_AC
20th October 2011, 11:16
But I don't know how to get access to the buttons.
Could you plese give an example how to implement the setter? I think I have to know the member of QAbstractSpinBox, wich is of StepEnabled, and which is used by the class to do it's own enabling / disabling of the button.
Please, so more help...

wysota
20th October 2011, 11:22
I don't understand your question. I think this is purely a matter of C++ skills. In doubt take a look at Qt source code how the method is implemented. This forum is not a place to teach you C++.

Markus_AC
20th October 2011, 11:26
One more try to explain:
I have implemented to stepEnabled() function.

But I really don't know how to get access to the buttons. So I don't know what I really have to do in my setter-function.
In QAbstractSpinBox there the enum (with the name) StepEnabled (first letter is capital letter where as the first letter of the function is a small letter). But this is just an enum, not a member-variable. So there is no access possible, either.