Results 1 to 9 of 9

Thread: Q_ENUMS, QItemEditorFactory

  1. #1
    Join Date
    Jan 2008
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Q_ENUMS, QItemEditorFactory

    I would like to register a QItemEditorCreatorBase that would handle properties represented as Q_ENUMS by presenting a QComboBox with a list of possible enum values represented as strings.

    I know how to make the QItemEditorCreatorBase but can't work out how to do the registration.
    QItemEditorFactory::registerEditor takes a QVariant::Type but how do I get a QVariant type id for an enum? I've tried a few things but got nowhere.

    Any help very gratefully received.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Q_ENUMS, QItemEditorFactory

    See Q_DECLARE_METATYPE().

  3. #3
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Q_ENUMS, QItemEditorFactory

    Or qRegisterMetaType() to be exact.
    J-P Nurmi

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Q_ENUMS, QItemEditorFactory

    Hmm... declaring the meta type should be enough, I think. qRegisterMetaType() is for using the type in signals and slots, isn't it? Or am I mistaken?

  5. #5
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Q_ENUMS, QItemEditorFactory

    You need the integer value returned by qRegisterMetaType() to be able to register editors to QItemEditorFactory.
    J-P Nurmi

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Q_ENUMS, QItemEditorFactory

    I guess using QMetaType::type() or qMetaTypeId() is an option as well.

  7. The following user says thank you to wysota for this useful post:

    jpn (16th January 2008)

  8. #7
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Q_ENUMS, QItemEditorFactory

    Quote Originally Posted by wysota View Post
    I guess using QMetaType::type() or qMetaTypeId() is an option as well.
    Ahh, seems so. Thanks, I hadn't noticed qMetaTypeId() before.
    J-P Nurmi

  9. #8
    Join Date
    Jan 2008
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Q_ENUMS, QItemEditorFactory

    Thanks for trying to help

    I had already tried Q_DECLARE_METATYPE() but never saw anything sensible when I tried to dump the QVariant.type().
    i.e.
    obj->getProperty("FOO").type()

    I always seemed to get QVariant::Int

    My workaround was to define a new subclass for QItemDelegate that holds a map from row to QMetaProperty and then examine QMetaProperty.isEnum(). Not very nice.

    I will try again with a tiny example and post the code here. There definitely is a discontinuity between enum and other types in the Qt MetaProperty model (but hey Trolltech are solving these difficult problems of mapping C++ into a more dynamic language so we don't have to .

    I think I should be reading this forum every day! You guys are way ahead of me with Qt.

    Thanks again

  10. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,018 Times in 4,794 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Q_ENUMS, QItemEditorFactory

    enums are really ints. You have to be sure you are explicitely telling the variant that you are not passing an integer but your enum. Could you show us the Q_PROPERTY declaration of the property and the setter method for the property?

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
  •  
Qt is a trademark of The Qt Company.