Results 1 to 2 of 2

Thread: QWizard, QComboBox and registerField() issue

  1. #1
    Join Date
    Jan 2008
    Posts
    56
    Thanks
    7
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default QWizard, QComboBox and registerField() issue

    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

  2. #2
    Join Date
    Jan 2008
    Posts
    56
    Thanks
    7
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QWizard, QComboBox and registerField() issue

    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.
    Qt Code:
    1. class QWizardComboBox : public QComboBox
    2. {
    3. Q_OBJECT
    4. QVariant currentItemData;
    5. public:
    6. QWizardComboBox(QWidget* parent=0) : QComboBox(parent)
    7. {
    8. currentItemData=QVariant();
    9. connect(this, SIGNAL(currentIndexChanged(int)), this, SLOT(onCurrentIdxChanged(int)));
    10. };
    11. Q_PROPERTY(QVariant currentItemData READ getCurrentItemData WRITE setCurrentItemData)
    12. QVariant getCurrentItemData() const {return currentItemData;};
    13. public Q_SLOTS:
    14. void onCurrentIdxChanged(int idx)
    15. {
    16. setCurrentItemData(itemData(idx));
    17. }
    18. void setCurrentItemData(QVariant data)
    19. {
    20. if (data!=currentItemData)
    21. {
    22. currentItemData=data;
    23. currentItemDataChanged(currentItemData);
    24. }
    25. }
    26. Q_SIGNALS:
    27. void currentItemDataChanged(QVariant);
    28. };
    To copy to clipboard, switch view to plain text mode 

    In the QWizard constructor, _before_ using setPage or addPage:
    Qt Code:
    1. 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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.