Creating Custom Widget ExtensionsOnce you have a custom widget plugin for Qt Designer, you can provide it with the expected behavior and functionality within Qt Designer's workspace, using custom widget extensions. Extension TypesThere are several available types of extensions in Qt Designer. You can use all of these extensions in the same pattern, only replacing the respective extension base class. QDesignerContainerExtension is necessary when implementing a custom multi-page container.
Qt Designer uses the QDesignerPropertySheetExtension and the QDesignerMemberSheetExtension classes to feed its property and signal and slot editors. Whenever a widget is selected in its workspace, Qt Designer will query for the widget's property sheet extension; likewise, whenever a connection between two widgets is requested, Qt Designer will query for the widgets' member sheet extensions. Warning: All widgets have default property and member sheets. If you implement custom property sheet or member sheet extensions, your custom extensions will override the default sheets. Creating an ExtensionTo create an extension you must inherit both QObject and the appropriate base class, and reimplement its functions. Since we are implementing an interface, we must ensure that it is made known to the meta object system using the Q_INTERFACES() macro in the extension class's definition. For example: class MyExtension: public QObject, public QdesignerContainerExtension { Q_OBJECT Q_INTERFACE(QDesignerContainerExtension) ... } This enables Qt Designer to use the qobject_cast() function to query for supported interfaces using a QObject pointer only. Exposing an Extension to Qt DesignerIn Qt Designer the extensions are not created until they are required. For this reason, when implementing extensions, you must subclass QExtensionFactory to create a class that is able to make instances of your extensions. Also, you must register your factory with Qt Designer's extension manager; the extension manager handles the construction of extensions. When an extension is requested, Qt Designer's extension manager will run through its registered factories calling QExtensionFactory::createExtension() for each of them until it finds one that is able to create the requested extension for the selected widget. This factory will then make an instance of the extension. The QExtensionFactory class provides a standard extension factory, but it can also be used as an interface for custom extension factories. The purpose is to reimplement the QExtensionFactory::createExtension() function, making it able to create your extension, such as a MultiPageWidget container extension. You can either create a new QExtensionFactory and reimplement the QExtensionFactory::createExtension() function: or you can use an existing factory, expanding the QExtensionFactory::createExtension() function to enable the factory to create your custom extension as well: When implementing a custom widget plugin, you must subclass the QDesignerCustomWidgetInterface to expose your plugin to Qt Designer. This is covered in more detail in the Creating Custom Widgets for Qt Designer section. The registration of an extension factory is typically made in the QDesignerCustomWidgetInterface::initialize() function: The formEditor parameter in the QDesignerCustomWidgetInterface::initialize() function is a pointer to Qt Designer's current QDesignerFormEditorInterface object. You must use the QDesignerFormEditorInterface::extensionManager() function to retrieve an interface to Qt Designer's extension manager. Then you use the QExtensionManager::registerExtensions() function to register your custom extension factory. For more information on creating custom widget extensions in Qt Designer, refer to the Task Menu Extension and Container Extension examples. |