PDA

View Full Version : QWizard, QComboBox and registerField() issue



RThaden
27th May 2008, 01:41
Hi all,

I have implemented a QWizard with several pages which have combo boxes.
I fill the boxes itemData fields (with ints), because I don't need the index of the selected item but the ints I put into the itemData.
With registerField() I can nicely get the current index, because QWizard automatically delivers it with an internal mechanism.

Is there a possibility to tell registerField() to store the QVariant of the itemData instead of the currentIndex().

If not, my solution would be, to store a list of the ints I put into the itemData, implement a Get function for the list and look up the int with the currentIndex I can retrieve with the field() method.
Or to drop the registerField() method and use my own signals to deliver the itemData of a comboBox from the current page to the QWizard instance and use Get methods to retrieve it from the outside.

What 's the best method here?

Any hint appreciated.

Thanks,

Rainer

RThaden
27th May 2008, 12:18
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.


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);
};


In the QWizard constructor, _before_ using setPage or addPage:

setDefaultProperty("QWizardComboBox", "currentItemData", "currentItemDataChanged");


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