Here is an example assuming the QVector is non-empty.
{
Q_OBJECT
public:
explicit SpinBox
(const QVector<int>
& values,
QWidget * parent
= 0) , mValues(values)
, mIndex(0)
{
qSort(mValues);
setMinimum(mValues.at(0));
setMaximum(mValues.at(mValues.size() - 1));
setValue(mValues.at(0));
}
protected:
void stepBy(int steps) // re-implementaion
{
mIndex += steps;
mIndex = qBound(0, mIndex, mValues.size() - 1);
setValue(mValues.at(mIndex));
}
private:
QVector<int> mValues;
int mIndex;
};
int main(int argc, char ** argv)
{
QVector<int> values = QVector<int>() << 100 << 20 << 25 << 36 << 42 << 56 << 98 << 105;
SpinBox spinbox(values);
spinbox.show();
return app.exec();
}
class SpinBox : public QSpinBox
{
Q_OBJECT
public:
explicit SpinBox(const QVector<int> & values, QWidget * parent = 0)
: QSpinBox(parent)
, mValues(values)
, mIndex(0)
{
qSort(mValues);
setMinimum(mValues.at(0));
setMaximum(mValues.at(mValues.size() - 1));
setValue(mValues.at(0));
}
protected:
void stepBy(int steps) // re-implementaion
{
mIndex += steps;
mIndex = qBound(0, mIndex, mValues.size() - 1);
setValue(mValues.at(mIndex));
}
private:
QVector<int> mValues;
int mIndex;
};
int main(int argc, char ** argv)
{
QApplication app(argc, argv);
QVector<int> values = QVector<int>() << 100 << 20 << 25 << 36 << 42 << 56 << 98 << 105;
SpinBox spinbox(values);
spinbox.show();
return app.exec();
}
To copy to clipboard, switch view to plain text mode
Bookmarks