QDesignerCustomWidgetCollectionInterface

The QDesignerCustomWidgetCollectionInterface class allows you to include several custom widgets in one single library. More

Inheritance diagram of PySide6.QtDesigner.QDesignerCustomWidgetCollectionInterface

Detailed Description

When implementing a custom widget plugin, you build it as a separate library. If you want to include several custom widget plugins in the same library, you must in addition subclass QDesignerCustomWidgetCollectionInterface .

QDesignerCustomWidgetCollectionInterface contains one single function returning a list of the collection’s QDesignerCustomWidgetInterface objects. For example, if you have several custom widgets CustomWidgetOne, CustomWidgetTwo and CustomWidgetThree, the class definition may look like this:

#include customwidgetoneinterface.h
#include customwidgettwointerface.h
#include customwidgetthreeinterface.h


class MyCustomWidgets(QObject, QDesignerCustomWidgetCollectionInterface):

    Q_OBJECT
    Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QDesignerCustomWidgetCollectionInterface")
    Q_INTERFACES(QDesignerCustomWidgetCollectionInterface)
# public
    MyCustomWidgets(QObject parent = 0)
customWidgets = QList()
# private
widgets = QList()

In the class constructor you add the interfaces to your custom widgets to the list which you return in the customWidgets() function:

def __init__(self, parent):
    QObject.__init__(self, parent)

    widgets.append(CustomWidgetOneInterface(self))
    widgets.append(CustomWidgetTwoInterface(self))
    widgets.append(CustomWidgetThreeInterface(self))

QList<QDesignerCustomWidgetInterface*> MyCustomWidgets::customWidgets()

    return widgets

Note that instead of exporting each custom widget plugin using the Q_PLUGIN_METADATA() macro, you export the entire collection. The Q_PLUGIN_METADATA() macro ensures that Qt Designer can access and construct the custom widgets. Without this macro, there is no way for Qt Designer to use them.

See also

QDesignerCustomWidgetInterface Creating Custom Widgets for Qt Designer

class PySide6.QtDesigner.QDesignerCustomWidgetCollectionInterface
PySide6.QtDesigner.QDesignerCustomWidgetCollectionInterface.customWidgets()
Return type

Returns a list of interfaces to the collection’s custom widgets.