Spin box of strings
-
Hi, i have to create a spinbox with strings instead of numbers.
Is there any simple way to set the spin box to use my QVector with strings?
If someone try to type any character which is not included in the vector, it should be rejected, if you increase or decrease, it should go by the index value, for examplea
b
c
dSo if i hit increase or upper arrow, the next after a should be b,etc.
-
Hi
why not use a QCombobox and 2 buttons to raise/decrease the active index ? -
@Loc888 you may want to subclass QSpinBox and use a list of accepted values in combination with the textFromValue() method. Pseudo-code follows:
textspinbox.h
class TextSpinBox : public QSpinBox { public: explicit TextSpinBox(QWidget *parent = 0); private: QString textFromValue(int value) const; QList<QString> acceptedValues; };
textspinbox.cpp
#include "textspinbox.h" TextSpinBox::TextSpinBox(QWidget *parent) : QSpinBox(parent) { acceptedValues << "First" << "Second" << "Third" << "Fourth"; setRange(1, acceptedValues.size()); } QString TextSpinBox::textFromValue(int value) const { return acceptedValues.value(value - 1); }
-
It helped, thank you for help much.
There was only one problem, if i set 0 - 20 range numbers, and add let's say few symbols before 0, a,b,cIf i type 13 in the spinBox, instead of 13 i get 10, because the symbols took 3 indexes, i fixed this issue by moving all the symbols after the numbers.