Nobody?
OK, think, I'll have to do it myself. Found the following solution:
Derive a class from QComboBox and give it a property currentItemData.
{
Q_OBJECT
public:
{
connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(onCurrentIdxChanged(int)));
};
Q_PROPERTY(QVariant currentItemData READ getCurrentItemData WRITE setCurrentItemData
) QVariant getCurrentItemData
() const {return currentItemData;
};
public Q_SLOTS:
void onCurrentIdxChanged(int idx)
{
setCurrentItemData(itemData(idx));
}
{
if (data!=currentItemData)
{
currentItemData=data;
currentItemDataChanged(currentItemData);
}
}
Q_SIGNALS:
};
class QWizardComboBox : public QComboBox
{
Q_OBJECT
QVariant currentItemData;
public:
QWizardComboBox(QWidget* parent=0) : QComboBox(parent)
{
currentItemData=QVariant();
connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(onCurrentIdxChanged(int)));
};
Q_PROPERTY(QVariant currentItemData READ getCurrentItemData WRITE setCurrentItemData)
QVariant getCurrentItemData() const {return currentItemData;};
public Q_SLOTS:
void onCurrentIdxChanged(int idx)
{
setCurrentItemData(itemData(idx));
}
void setCurrentItemData(QVariant data)
{
if (data!=currentItemData)
{
currentItemData=data;
currentItemDataChanged(currentItemData);
}
}
Q_SIGNALS:
void currentItemDataChanged(QVariant);
};
To copy to clipboard, switch view to plain text mode
In the QWizard constructor, _before_ using setPage or addPage:
setDefaultProperty("QWizardComboBox", "currentItemData", "currentItemDataChanged");
setDefaultProperty("QWizardComboBox", "currentItemData", "currentItemDataChanged");
To copy to clipboard, switch view to plain text mode
This tells the wizard to use the property currentItemData whenever the signal currentItemDataChanged is emitted (instead of currentIndex and currentIndexChanged).
Hope that helps anyone.
Regards,
Rainer
Bookmarks