PDA

View Full Version : Q_ENUMS, QItemEditorFactory



Kunchok
12th January 2008, 07:19
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.

wysota
13th January 2008, 16:56
See Q_DECLARE_METATYPE().

jpn
16th January 2008, 11:07
Or qRegisterMetaType() to be exact. ;)

wysota
16th January 2008, 11:14
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?

jpn
16th January 2008, 11:16
You need the integer value returned by qRegisterMetaType() to be able to register editors to QItemEditorFactory.

wysota
16th January 2008, 12:37
I guess using QMetaType::type() or qMetaTypeId() is an option as well.

jpn
16th January 2008, 12:40
I guess using QMetaType::type() or qMetaTypeId() is an option as well.
Ahh, seems so. Thanks, I hadn't noticed qMetaTypeId() before. :)

Kunchok
21st January 2008, 00:56
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

wysota
21st January 2008, 12:20
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?