Wladimir J. van der Laan
14 years ago
19 changed files with 151 additions and 33 deletions
@ -0,0 +1,27 @@
@@ -0,0 +1,27 @@
|
||||
#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(); |
||||
} |
@ -0,0 +1,33 @@
@@ -0,0 +1,33 @@
|
||||
#ifndef QVALUECOMBOBOX_H |
||||
#define QVALUECOMBOBOX_H |
||||
|
||||
#include <QComboBox> |
||||
|
||||
// QComboBox that can be used with QDataWidgetMapper to select
|
||||
// ordinal values from a model.
|
||||
class QValueComboBox : public QComboBox |
||||
{ |
||||
Q_OBJECT |
||||
Q_PROPERTY(int value READ value WRITE setValue NOTIFY valueChanged USER true); |
||||
public: |
||||
explicit QValueComboBox(QWidget *parent = 0); |
||||
|
||||
int value() const; |
||||
void setValue(int value); |
||||
|
||||
// Model role to use as value
|
||||
void setRole(int role); |
||||
|
||||
signals: |
||||
void valueChanged(); |
||||
|
||||
public slots: |
||||
|
||||
private: |
||||
int role; |
||||
|
||||
private slots: |
||||
void handleSelectionChanged(int idx); |
||||
}; |
||||
|
||||
#endif // QVALUECOMBOBOX_H
|
Loading…
Reference in new issue