CopperSpice API  1.7.4
Creating Custom Widget Extensions

Once you have a custom widget plugin for the Designer application you can add functionality using custom widget extensions.

Extension Types

There are several types of extensions in CS 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.

QDesignerTaskMenuExtension is useful for custom widgets. It provides an extension that allow you to add custom menu entries to the CS Designer task menu.
QDesignerContainerExtension is necessary when implementing a custom multi-page container. It provides an extension that allows you to add and delete pages for a multi-page container plugin in CS Designer. Note: It is not possible to add custom per-page properties for some widgets (e.g., QTabWidget) due to the way they are implemented.
The QDesignerMemberSheetExtension class allows you to manipulate a widget's member functions displayed when connecting signals and slots.
QDesignerPropertySheetExtension, QDesignerDynamicPropertySheetExtension
These extension classes allow you to control how a widget's properties are displayed in the CS Designer property editor.

CS 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, CS Designer will query for the widget's property sheet extension. Likewise, whenever a connection between two widgets is requested, CS Designer will query for the widgets member sheet extensions.

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 Extension

To 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 CS_INTERFACES() macro in the extension class definition. For example:

class MyExtension : public QObject, public QDesignerContainerExtension

This enables CS Designer to use the qobject_cast() function to query for supported interfaces using a QObject pointer only.

Exposing an Extension to CS Designer

In CS 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 the CS Designer extension manager. The extension manager handles the construction of extensions.

When an extension is requested, CS 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.

Creating an Extension Factory

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 possible to create your extension.

You can either create a new QExtensionFactory and reimplement the QExtensionFactory::createExtension() function:

QObject *ANewExtensionFactory::createExtension(QObject *object,
const QString &iid, QObject *parent) const
if (iid != Q_TYPEID(QDesignerContainerExtension)) {
return 0;
if (MyCustomWidget *widget = qobject_cast<MyCustomWidget* > (object)) {
return new MyContainerExtension(widget, parent);
return 0;

or you can use an existing factory, expanding the QExtensionFactory::createExtension() function to enable the factory to create your custom extension as well:

QObject *AGeneralExtensionFactory::createExtension(QObject *object, const QString &iid, QObject *parent) const
MyCustomWidget *widget = qobject_cast<MyCustomWidget*>(object);
if (widget && (iid == Q_TYPEID(QDesignerTaskMenuExtension))) {
return new MyTaskMenuExtension(widget, parent);
} else if (widget && (iid == Q_TYPEID(QDesignerContainerExtension))) {
return new MyContainerExtension(widget, parent);
} else {
return 0;

Accessing the Designer Extension Manager

When implementing a custom widget plugin, you must subclass the QDesignerCustomWidgetInterface to expose your plugin to CS Designer. This is covered in more detail in the Creating Custom Widgets. The registration of an extension factory is typically made in the QDesignerCustomWidgetInterface::initialize() function:

void MyPlugin::initialize(QDesignerFormEditorInterface *formEditor)
if (initialized) {
QExtensionManager *manager = formEditor->extensionManager();
Q_ASSERT(manager != 0);
manager->registerExtensions(new MyExtensionFactory(manager), Q_TYPEID(QDesignerTaskMenuExtension));
initialized = true;

The formEditor parameter in the QDesignerCustomWidgetInterface::initialize() function is a pointer to CS Designer's current QDesignerFormEditorInterface object. You must use the QDesignerFormEditorInterface::extensionManager() function to retrieve an interface to CS Designer's extension manager. Then you use the QExtensionManager::registerExtensions() function to register your custom extension factory.