Details
-
Bug
-
Resolution: Invalid
-
P2: Important
-
None
-
5.12.2
-
None
Description
For a Qt Creator plugin project, I needed to get only those properties of the widgets which Qt Designer shows in the Property Editor.
I read the topic Reading and Writing Properties with the Meta-Object System from the docs at https://doc.qt.io/qt-5/properties.html, I successfully read the properties of QPushButton using the following code:
QObject *object = new QPushButton; const QMetaObject *metaobject = object->metaObject(); int count = metaobject->propertyCount(); for (int i=0; i<count; ++i) { QMetaProperty metaproperty = metaobject->property(i); qDebug()<<qPrintable(QString(metaproperty.name()) + " : " + QString(metaproperty.typeName())); }
I noticed that the above code printed not only those properties which Qt Designer displays for the QPushButton in the Property Editor but also many other too!
In the docs i found isDesignable https://doc.qt.io/Qt-5/qmetaproperty.html#isDesignable ,
As the docs says here https://doc.qt.io/qt-5/properties.html that:
"The DESIGNABLE attribute indicates whether the property should be visible in the property editor of GUI design tool (e.g., Qt Designer). "
So I included metaproperty.isDesignable() check in the code so that my code may print only those properties which are intended to be visible in the Qt Designer:
QObject *object = new QPushButton; const QMetaObject *metaobject = object->metaObject(); int count = metaobject->propertyCount(); for (int i=0; i<count; ++i) { QMetaProperty metaproperty = metaobject->property(i); if( metaproperty.isDesignable() ) { qDebug()<<qPrintable(QString(metaproperty.name()) + " : " + QString(metaproperty.typeName())); } }
But even with this check I noticed that many properties get printed which are not shown in the Qt Designer!
For example, these properties are shown which I don't find them in Qt Designer:
windowModality, frameGeometry, normalGeometry, childrenRect, windowIcon, windowIconText, windowOpacity, windowModified, etc.