Monday, November 26, 2012

QDataWidgetMapper and QComboBox

Just came across a small drawback, when using QDataWidgetMapper and trying to add a mapping to a QComboBox. Unfortunately, QComboBox implements the USER property like this:

 Q_PROPERTY(QString currentText READ currentText USER true)  

Since it only declares the READ function, this means that it is not possible to e.g. use a QDataWidgetMapper and a QComboBox to sync contents to a model. One workaround would be to subclass QComboBox and implement a WRITE and NOTIFY function as shown below.