title: Set specific values in a QSpinBox
body: <p>I have a widget containing a <code>QSpinBox</code>. This widget also has a <code>QVector&lt;int&gt; Values</code>. What I would like to do is get the <code>QSpinBox</code> to display values issued <strong>from <code>Values</code> only</strong>.</p>
  
  <p>At first I thought that a new slot and signal in my widget would do the trick, something like </p>
  
  <p>slot :</p>
  
  <pre><code>void ChangeSomeValue()
  {
      // QVector&lt;int&gt; Values;
      // int Index;
      int val = Values[ Index ];
      emit( SomeValueChanged( val ) );
  }
  </code></pre>
  
  <p>connects :</p>
  
  <pre><code>connect( UI-&gt;MySpinBox, SIGNAL( valueChanged(int) ), this, SLOT( ChangeSomeValue() ) );
  connect( this, SIGNAL( SomeValueChanged(int ) ), UI-&gt;MySpinBox, SLOT( setValue(int) ) );
  </code></pre>
  
  <p>But then several problems arise :</p>
  
  <ol>
  <li><code>QSpinBox</code> emit another <code>valueChanged</code> after I call its setValue, resulting in an infinite loop (until my <code>QVector</code> explodes). </li>
  <li>I still have to find a way to keep track of Index, depending on which of the <code>QSpinBox</code> arrows was clicked (up or down... I don't even think this is possible).</li>
  </ol>
  
  <p>So my solution, with its problems, seems to be a dead end. Any idea?. I'd like to stick to <code>QSpinBox</code>, if possible.</p>
  
  <p>Thanks !</p>
  
  <p><strong>[EDIT]</strong></p>
  
  <p>Subclassing :</p>
  
  <pre><code>class SpinBox : public QSpinBox
  {
      Q_OBJECT
  public:
      explicit SpinBox(const QVector&lt;int&gt; &amp; 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&lt;int&gt;    mValues;
      int             mIndex;
  };
  </code></pre>