QDataWidgetMapper ignoring inheritance

299 Views Asked by At

I have a model that is being displayed in a set of widgets using a QDataWidgetMapper. One such field is a QComboBox populated by a QStringList of options, but the mapping doesn't seem to work.

QComboBox's user property is the currentText() function, which has no corresponding setCurrentText() function for writing, so the mapping fails with the warning Warning: QComboBox::setProperty: Property "currentText" invalid, read-only or does not exist.

Therefore, I created a simple custom QComboBox like the following:

class MappingComboBox : public QComboBox
{
    Q_OBJECT
public:
    Q_PROPERTY(QString mappingText READ currentText WRITE setCurrentText USER true)

    explicit MappingComboBox(QWidget *parent = 0) : QComboBox(parent) {}
    QString currentText() const { return QComboBox::currentText(); }

public slots:
    void setCurrentText(const QString& s) { setCurrentIndex(findText(s); }
};

But I still get the same mapping error Warning: QComboBox::setProperty: Property "currentText" invalid, read-only or does not exist. I'm quite certain that I have promoted my widgets to be MappingComboBoxes, yet the QDataWidgetMapper still appears to be using the default read-only user property currentText instead of the writable custom user property mappingText.

Am I missing something? Can you not override an inherited class's user property?

Edit: I recognize that this issue is fixed in Qt 5.3.1, but I'm stuck in Qt 4 for the time being so I'm trying to come up with a workaround that doesn't involve editing the source.

0

There are 0 best solutions below