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.
Re: Q_ENUMS, QItemEditorFactory
See Q_DECLARE_METATYPE().
Re: Q_ENUMS, QItemEditorFactory
Or qRegisterMetaType() to be exact. ;)
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?
Re: Q_ENUMS, QItemEditorFactory
You need the integer value returned by qRegisterMetaType() to be able to register editors to QItemEditorFactory.
Re: Q_ENUMS, QItemEditorFactory
I guess using QMetaType::type() or qMetaTypeId() is an option as well.
Re: Q_ENUMS, QItemEditorFactory
Quote:
Originally Posted by
wysota
Ahh, seems so. Thanks, I hadn't noticed qMetaTypeId() before. :)
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
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?