The object controller class.
This is a special "magical" widget. It allows to show the meta properties and dynamic property (see Qt Object Model / Property for lmore information on these).
A complete example that show the usability of object controller is available in applications "objectcontroller". The best way to learn how to use this Core facility is to look at this application and the given TestClass.
An object controller is a sort of property browser where each line represents a property. The object controller automatically build a GUI to access and optionally changed the properties you defined.
There could be many different types of properties, and as many as you want.
In order to handle a list of specific properties for your class, you have two choices:
- write a new class inheriting from QObject and declare as many Q_PROPERTY as needed. When send to the ObjectController class the Q_PROPERTY list will be read and the GUI interfaces build.
- generate dynamic properties on-the-fly
The second choice does even not need a new class. You have to create a new QObject instance, and add as many dynamic properties as you wish using QObject::setProperty method. You also have to install an event monitor in your class to be notified when a property has changed (see TestClass in "objectcontroller" application).
Three different view mode are available to represent/interact with the property values:
- TREE based on a list view
- GROUPBOX same as TREE, but each group of properties are viewed in a group box
- BUTTON same as GROUPBOX, but buttons allow to show/hide the sub properties
The view mode can be changed at any time, even at run-time (see the "objectcontroller" application).
How to use this class:
- the constructor, to create the widget:
- to view/interact with the properties of a given QObject:
theController->setObject(myObject);
- to change the view mode:
- Note
- And... that's it! This method is easier, but does not work well for Q_ENUMS (enumerator). If you have an enum/Q_ENUMS property, you have to use the second method below.
The available property type are (see example in the "objectcontroller" application (tutorials), and see also QtVariantProperty in tools/qpropertybrowser for a complete list of associated constraints):
Property Type | Property Type Id |
int | QVariant::Int |
double | QVariant::Double |
bool | QVariant::Bool |
QString | QVariant::String |
QVector3D | QVariant::QVector3D |
QColor | QVariant::Color |
QDate | QVariant::Date |
QTime | QVariant::Time |
QChar | QVariant::Char |
QDateTime | QVariant::DateTime |
QPoint | Variant::Point |
QPointF | QVariant::PointF |
QKeySequence | QVariant::KeySequence |
QLocale | QVariant::Locale |
QSize | QVariant::Size |
QSizeF | QVariant::SizeF |
QRect | QVariant::Rect |
QRectF | QVariant::RectF |
QSizePolicy | QVariant::SizePolicy |
QFont | QVariant::Font |
QCursor | QVariant::Cursor |
enum | enumTypeId() |
flag | flagTypeId() |
group | groupTypeId() |
- Note
- in Q_PROPERTY if you don't specify a WRITE method, then the property is set as read only.