Display comboBox like list with Q_PROPERTY
-
Ah, so you want a property editor?
The one used in Qt Designer itself is available to you, but there are also 3rd party options. I have personally used YAPE (Yet Another Property Editor) that is available as a download from qt-app.org in the widgets section. There are others there as well.
-
Hi Andre,
Just for your information i have done it without use of property editor. As i want ti display comboBox in property editor of my custom widget. Following is the syntax of Q_PROPERTY to display like combobox in property editor in Qt designer.
Q_PROPERTY(CustomWidget::ParamTypeList ParamType READ getParamType WRITE setParamType)
-
Hi Neel,
i need to develop some activex controls with qt. Then , i want to display comboBox in property editor of my custom widget, just like you. But i haven't find method , can you help me ? i see you said like "Q_PROPERTY(CustomWidget::ParamTypeList ParamType READ getParamType WRITE setParamType)" , but what's the type of CustomWidget::ParamTypeList ? and how to define getParamType(or set) function?thanks,
shootstar -
i guess the property editor creates a combo box if the property is an enum type.
-
[quote author="shootstar" date="1370589776"]hi raven-worx, thank you for your replay!
i have use an enum type ,like "enum ParamTypeList{...}", but it also not solve my problem, and if the property defined as enum, it will not be displayed in the property page.
[/quote]
i think you also have to specify the "Q_ENUMS macro":http://qt-project.org/doc/qt-4.8/qobject.html#Q_ENUMS in your class definition so Qt knows about it -
just to make sure: you subclass QObject (or a class which inherits QObject) and you have Q_OBJECT macro specified?
-
my .h file just like this:
class AxisCoord : public QWidget, public QAxBindable
{
Q_OBJECT
Q_ENUMS(ParamTypeList)
Q_PROPERTY( QString nctype READ GetType WRITE SetType)
Q_PROPERTY( int value READ value WRITE setValue )
Q_PROPERTY(ParamTypeList ParamType READ getParamType WRITE setParamType)public:
AxisCoord(QWidget *parent = 0);QString GetType() const;
int value() const;
enum ParamTypeList
{
TYPE1,
TYPE2,
TYPE3
};ParamTypeList getParamType() const;
... //other code
} -
my .h file just like this:
@class AxisCoord : public QWidget, public QAxBindable
{
Q_OBJECT
Q_ENUMS(ParamTypeList)
Q_PROPERTY( QString nctype READ GetType WRITE SetType)
Q_PROPERTY( int value READ value WRITE setValue )
Q_PROPERTY(ParamTypeList ParamType READ getParamType WRITE setParamType)public:
AxisCoord(QWidget *parent = 0);QString GetType() const;
int value() const;enum ParamTypeList
{
TYPE1,
TYPE2,
TYPE3
};ParamTypeList getParamType() const;
QComboBox getCombobox() const;
...//other code
@ -
hmm...please clean your project, rerun qmake and try again.
I don't think that i makes a difference but you can give it also a try: specify the Q_ENUMS macro after the Q_PROPERTY macros. Like in this "example":http://qt-project.org/doc/qt-4.8/properties.html#a-simple-example.
-
hi, raven-worx, i encounter a new problem. now, the property can be displayed, but when i modify the QAxWidget property which displayed in comboBox(include defined property), as:
@ //ui_test_active.h
axWidget->setProperty("FocusPolicy", QVariant(QAxWidget::NoFocus));
axWidget->setProperty("ParamType", QVariant(QAxWidget::TYPE2));
axWidget->setProperty("cursor", QVariant(QAxWidget::UpArrowCursor));
@
you know, the "FocusPolicy" and "cursor" property are the defualt property, only the "ParamType" is the new property. but when i build the project, there are errors, as:
@1>E:\HNC11\test_active\test_active\GeneratedFiles\ui_test_active.h(45): error C2039: 'NoFocus' : is not a member of 'QAxWidget'
1> d:\qt\qt5.0.2\5.0.2\msvc2010\include\activeqt\qaxwidget.h(59) : see declaration of 'QAxWidget'
1>E:\HNC11\test_active\test_active\GeneratedFiles\ui_test_active.h(45): error C2065: 'NoFocus' : undeclared identifier
1>E:\HNC11\test_active\test_active\GeneratedFiles\ui_test_active.h(46): error C2039: 'TYPE2' : is not a member of 'QAxWidget'
1> d:\qt\qt5.0.2\5.0.2\msvc2010\include\activeqt\qaxwidget.h(59) : see declaration of 'QAxWidget'
1>E:\HNC11\test_active\test_active\GeneratedFiles\ui_test_active.h(46): error C2065: 'TYPE2' : undeclared identifier
1>E:\HNC11\test_active\test_active\GeneratedFiles\ui_test_active.h(48): error C2039: 'UpArrowCursor' : is not a member of 'QAxWidget'
1> d:\qt\qt5.0.2\5.0.2\msvc2010\include\activeqt\qaxwidget.h(59) : see declaration of 'QAxWidget'
1>E:\HNC11\test_active\test_active\GeneratedFiles\ui_test_active.h(48): error C2065: 'UpArrowCursor' : undeclared identifier@
i have no idea to solve those error, can you help? -
[quote author="shootstar" date="1370658202"]
you know, the "FocusPolicy" and "cursor" property are the defualt property, only the "ParamType" is the new property. but when i build the project, there are errors[/quote]the compiler error says it all: "error C2039: 'NoFocus' : is not a member of 'QAxWidget'"
Your enum values are not defined in QAxWidegt but in Qt namespace. So use Qt::NoFocus and Qt::UpArrowCursor.And btw. why do you use to set these properties with with the setter for dynamic properties (i mean the setProperty() method)? I think there is nothing wrong with this code, but it is more error prone and there are qwidget setters available.
-
thank you for your help!
the code which in "ui_test_active.h" is automatically created by the system, i just modify the activeX property in Qt designer, then the system automatically generates those codes ("ui_test_active.h" file), so how can i do? whether is there some wrongs with my system configuration?