28 lines
553 B
C++
28 lines
553 B
C++
|
#include "qvaluecombobox.h"
|
||
|
|
||
|
QValueComboBox::QValueComboBox(QWidget *parent) :
|
||
|
QComboBox(parent), role(Qt::UserRole)
|
||
|
{
|
||
|
connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(handleSelectionChanged(int)));
|
||
|
}
|
||
|
|
||
|
int QValueComboBox::value() const
|
||
|
{
|
||
|
return itemData(currentIndex(), role).toInt();
|
||
|
}
|
||
|
|
||
|
void QValueComboBox::setValue(int value)
|
||
|
{
|
||
|
setCurrentIndex(findData(value, role));
|
||
|
}
|
||
|
|
||
|
void QValueComboBox::setRole(int role)
|
||
|
{
|
||
|
this->role = role;
|
||
|
}
|
||
|
|
||
|
void QValueComboBox::handleSelectionChanged(int idx)
|
||
|
{
|
||
|
emit valueChanged();
|
||
|
}
|