
We bake cookies in your browser for a better experience. Using this site means that you consent.Read More
TheQDesignerPropertySheetExtension class allows you to manipulate a widget's properties which is displayed in Qt Designer's property editor.More...
| Header: | #include <QDesignerPropertySheetExtension> |
| virtual | ~QDesignerPropertySheetExtension() |
| virtual int | count() const = 0 |
| virtual bool | hasReset(int index) const = 0 |
| virtual int | indexOf(const QString & name) const = 0 |
| virtual bool | isAttribute(int index) const = 0 |
| virtual bool | isChanged(int index) const = 0 |
| virtual bool | isVisible(int index) const = 0 |
| virtual QVariant | property(int index) const = 0 |
| virtual QString | propertyGroup(int index) const = 0 |
| virtual QString | propertyName(int index) const = 0 |
| virtual bool | reset(int index) = 0 |
| virtual void | setAttribute(int index, bool attribute) = 0 |
| virtual void | setChanged(int index, bool changed) = 0 |
| virtual void | setProperty(int index, const QVariant & value) = 0 |
| virtual void | setPropertyGroup(int index, const QString & group) = 0 |
| virtual void | setVisible(int index, bool visible) = 0 |
TheQDesignerPropertySheetExtension class allows you to manipulate a widget's properties which is displayed in Qt Designer's property editor.
QDesignerPropertySheetExtension provides a collection of functions that are typically used to query a widget's properties, and to manipulate the properties' appearance in the property editor. For example:
QDesignerPropertySheetExtension*propertySheet=0;QExtensionManager manager= formEditor->extensionManager();propertySheet= qt_extension<QDesignerPropertySheetExtension*>(manager, widget);int index= propertySheet->indexOf(QLatin1String("margin"));propertySheet->setProperty(index,10);propertySheet->setChanged(index,true);delete propertySheet;
Note that if you change the value of a property using theQDesignerPropertySheetExtension::setProperty() function, the undo stack is not updated. To ensure that a property's value can be reverted using the undo stack, you must use theQDesignerFormWindowCursorInterface::setProperty() function, or its buddysetWidgetProperty(), instead.
When implementing a custom widget plugin, a pointer toQt Designer's currentQDesignerFormEditorInterface object (formEditor in the example above) is provided by theQDesignerCustomWidgetInterface::initialize() function's parameter.
The property sheet, or any other extension, can be retrieved by queryingQt Designer's extension manager using theqt_extension() function. When you want to release the extension, you only need to delete the pointer.
All widgets have a default property sheet which populatesQt Designer's property editor with the widget's properties (i.e the ones defined with theQ_PROPERTY() macro). ButQDesignerPropertySheetExtension also provides an interface for creating custom property sheet extensions.
Warning:Qt Designer uses theQDesignerPropertySheetExtension to feed its property editor. Whenever a widget is selected in its workspace,Qt Designer will query for the widget's property sheet extension. If the selected widget has an implemented property sheet extension, this extension will override the default property sheet.
To create a property sheet extension, your extension class must inherit from bothQObject andQDesignerPropertySheetExtension. Then, since we are implementing an interface, we must ensure that it's made known to the meta object system using theQ_INTERFACES() macro:
class MyPropertySheetExtension :publicQObject,publicQDesignerPropertySheetExtension{ Q_OBJECT Q_INTERFACES(QDesignerPropertySheetExtension)public:...}
This enablesQt Designer to useqobject_cast() to query for supported interfaces using nothing but aQObject pointer.
InQt Designer the extensions are not created until they are required. For that reason, when implementing a property sheet extension, you must also create aQExtensionFactory, i.e a class that is able to make an instance of your extension, and register it usingQt Designer'sextension manager.
When a property sheet extension is required,Qt Designer'sextension manager will run through all its registered factories callingQExtensionFactory::createExtension() for each until the first one that is able to create a property sheet extension for the selected widget, is found. This factory will then make an instance of the extension. If no such factory can be found,Qt Designer will use the default property sheet.
There are four available types of extensions inQt Designer:QDesignerContainerExtension,QDesignerMemberSheetExtension,QDesignerPropertySheetExtension andQDesignerTaskMenuExtension. Qt Designer's behavior is the same whether the requested extension is associated with a multi page container, a member sheet, a property sheet or a task menu.
TheQExtensionFactory class provides a standard extension factory, and can also be used as an interface for custom extension factories. You can either create a newQExtensionFactory and reimplement theQExtensionFactory::createExtension() function. For example:
QObject*ANewExtensionFactory::createExtension(QObject*object,constQString&iid,QObject*parent)const{if (iid!= Q_TYPEID(QDesignerPropertySheetExtension))return0;if (MyCustomWidget*widget= qobject_cast<MyCustomWidget*> (object))returnnew MyPropertySheetExtension(widget, parent);return0;}
Or you can use an existing factory, expanding theQExtensionFactory::createExtension() function to make the factory able to create a property sheet extension extension as well. For example:
QObject*AGeneralExtensionFactory::createExtension(QObject*object,constQString&iid,QObject*parent)const{ MyCustomWidget*widget= qobject_cast<MyCustomWidget*>(object);if (widget&& (iid== Q_TYPEID(QDesignerTaskMenuExtension))) {returnnew MyTaskMenuExtension(widget, parent); }elseif (widget&& (iid== Q_TYPEID(QDesignerPropertySheetExtension))) {returnnew MyPropertySheetExtension(widget, parent); }else {return0; }}
For a complete example using an extension class, see theTask Menu Extension example. The example shows how to create a custom widget plugin for Qt Designer, and how to to use theQDesignerTaskMenuExtension class to add custom items toQt Designer's task menu.
See alsoQDesignerDynamicPropertySheetExtension,QExtensionFactory,QExtensionManager, andCreating Custom Widget Extensions.
[virtual]QDesignerPropertySheetExtension::~QDesignerPropertySheetExtension()Destroys the property sheet extension.
[pure virtual]int QDesignerPropertySheetExtension::count() constReturns the selected widget's number of properties.
[pure virtual]bool QDesignerPropertySheetExtension::hasReset(int index) constReturns true if the property at the givenindex has a reset button inQt Designer's property editor, otherwise false.
[pure virtual]int QDesignerPropertySheetExtension::indexOf(constQString & name) constReturns the index for a given propertyname.
See alsopropertyName().
[pure virtual]bool QDesignerPropertySheetExtension::isAttribute(int index) constReturns true if the property at the givenindex is an attribute, which will beexcluded from the UI file, otherwise false.
See alsoindexOf() andsetAttribute().
[pure virtual]bool QDesignerPropertySheetExtension::isChanged(int index) constReturns true if the value of the property at the givenindex differs from the property's default value, otherwise false.
See alsoindexOf(),setChanged(), andreset().
[pure virtual]bool QDesignerPropertySheetExtension::isVisible(int index) constReturns true if the property at the givenindex is visible inQt Designer's property editor, otherwise false.
See alsoindexOf() andsetVisible().
[pure virtual]QVariant QDesignerPropertySheetExtension::property(int index) constReturns the value of the property at the givenindex.
See alsoindexOf(),setProperty(), andpropertyGroup().
[pure virtual]QString QDesignerPropertySheetExtension::propertyGroup(int index) constReturns the property group for the property at the givenindex.
Qt Designer's property editor supports property groups, i.e. sections of related properties. A property can be related to a group using thesetPropertyGroup() function. The default group of any property is the name of the class that defines it. For example, theQObject::objectName property appears within theQObject property group.
See alsoindexOf() andsetPropertyGroup().
[pure virtual]QString QDesignerPropertySheetExtension::propertyName(int index) constReturns the name of the property at the givenindex.
See alsoindexOf().
[pure virtual]bool QDesignerPropertySheetExtension::reset(int index)Resets the value of the property at the givenindex, to the default value. Returns true if a default value could be found, otherwise false.
See alsoindexOf(),hasReset(), andisChanged().
[pure virtual]void QDesignerPropertySheetExtension::setAttribute(int index,bool attribute)Ifattribute is true, the property at the givenindex is made an attribute which will beexcluded from the UI file; otherwise it will be included.
See alsoindexOf() andisAttribute().
[pure virtual]void QDesignerPropertySheetExtension::setChanged(int index,bool changed)Sets whether the property at the givenindex is different from its default value, or not, depending on thechanged parameter.
See alsoindexOf() andisChanged().
[pure virtual]void QDesignerPropertySheetExtension::setProperty(int index, constQVariant & value)Sets thevalue of the property at the givenindex.
Warning: If you change the value of a property using this function, the undo stack is not updated. To ensure that a property's value can be reverted using the undo stack, you must use theQDesignerFormWindowCursorInterface::setProperty() function, or its buddysetWidgetProperty(), instead.
See alsoindexOf(),property(), andpropertyGroup().
[pure virtual]void QDesignerPropertySheetExtension::setPropertyGroup(int index, constQString & group)Sets the property group for the property at the givenindex togroup.
Relating a property to a group makes it appear within that group's section in the property editor. The default property group of any property is the name of the class that defines it. For example, theQObject::objectName property appears within theQObject property group.
See alsoindexOf(),property(), andpropertyGroup().
[pure virtual]void QDesignerPropertySheetExtension::setVisible(int index,bool visible)Ifvisible is true, the property at the givenindex is visible inQt Designer's property editor; otherwise the property is hidden.
© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.