Get previous value of QComboBox, which is in a QTableWidget, when the value is changed

前端 未结 4 989
长情又很酷
长情又很酷 2021-02-09 16:55

Say I have a QTableWidget and in each row there is a QComboBox and a QSpinBox. Consider that I store their values is a QMap

4条回答
  •  失恋的感觉
    2021-02-09 17:39

    How about creating your own, derived QComboBox class, something along the lines of:

    class MyComboBox : public QComboBox
    {
      Q_OBJECT
    private:
      QString _oldText;
    public:
      MyComboBox(QWidget *parent=0) : QComboBox(parent), _oldText() 
      {
        connect(this,SIGNAL(editTextChanged(const QString&)), this, 
            SLOT(myTextChangedSlot(const QString&)));
        connect(this,SIGNAL(currentIndexChanged(const QString&)), this, 
            SLOT(myTextChangedSlot(const QString&)));
      }
    private slots:
      myTextChangedSlot(const QString &newText)
      {
        emit myTextChangedSignal(_oldText, newText);
        _oldText = newText;
      }
    signals:
      myTextChangedSignal(const QString &oldText, const QString &newText);  
    };
    

    And then just connect to myTextChangedSignal instead, which now additionally provides the old combo box text.

    I hope that helps.

提交回复
热议问题