Last active
December 26, 2015 20:58
-
-
Save mistic100/cb2ae486ccac982a4699 to your computer and use it in GitHub Desktop.
[Qt/C++] QComboBox With direct access to item data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef QCOMBOBOXEXT_H | |
#define QCOMBOBOXEXT_H | |
#include <QWidget> | |
#include <QComboBox> | |
/** | |
* @brief QComboBox With direct access to item data | |
* @signal currentDataChanged(QVariant) | |
*/ | |
class QComboBoxExt : public QComboBox | |
{ | |
Q_OBJECT | |
public: | |
QComboBoxExt(QWidget* _parent = 0) : QComboBox(_parent) { | |
connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(on_currentIndexChanged(int))); | |
} | |
void setCurrentData(const QVariant &_data) | |
{ | |
setCurrentIndex(findData(_data)); | |
} | |
QVariant currentData() | |
{ | |
return itemData(currentIndex()); | |
} | |
signals: | |
void currentDataChanged(QVariant); | |
private slots: | |
void on_currentIndexChanged(int index) | |
{ | |
emit currentDataChanged(itemData(index)); | |
} | |
}; | |
#endif // QCOMBOBOXEXT_H |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment