#include <qwpcombobox.h>
Public Slots | |
| void | setCurrentKey (const QVariant &key) |
Public Member Functions | |
| QwpComboBox (QWidget *parent=0) | |
| QVariant | itemKey (int index) const |
| QVariant | currentKey () const |
Properties | |
| QVariant | currentKey |
The reason that this class exists is to allow comboboxes to be used with the SettingsController::bind() feature in a way that is useful.
For example, you may have a dynamic combox-box full of SQL drivers, where the "key" is Qt's SQL driver name (e.g. "QPSQL") and the text is a user-friendly version of the driver name (e.g. "PostgreSQL"). In this case, using QComboBox's only read-write "current" property for persistent storage would not only be meaningless by value, but whenever the set of available drivers changes the value could point to different driver items. Thus the currentKey property is used for storage and synchronisation. (Note: The currentText couldn't be used either, as it should be language dependant and may be changed or other reasons, whereas the stored value shouldn't).
The currentKey uses the Qt::UserRole. Thus, the key and text pair can set using one of the following lines:
addItem( text, key ); insertItem( text, key );
| QwpComboBox::QwpComboBox | ( | QWidget * | parent = 0 |
) |
Constructs a combobox with the given parent.
| QVariant QwpComboBox::itemKey | ( | int | index | ) | const |
Consistency method. Equalivant to itemData(index, Qt::UserRole).
| QVariant QwpComboBox::currentKey | ( | ) | const |
| void QwpComboBox::setCurrentKey | ( | const QVariant & | key | ) | [slot] |
Method required for the writing the currentKey property.
QVariant QwpComboBox::currentKey [read, write] |
Method required for the reading the currentKey property.
1.5.2