PySide6.QtDesigner.QDesignerCustomWidgetCollectionInterface¶
- class QDesignerCustomWidgetCollectionInterface¶
The
QDesignerCustomWidgetCollectionInterfaceclass allows you to include several custom widgets in one single library.Details
Warning
This section contains snippets that were automatically translated from C++ to Python and may contain errors.
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.QDesignerCustomWidgetCollectionInterfacecontains one single function returning a list of the collection’sQDesignerCustomWidgetInterfaceobjects. For example, if you have several custom widgetsCustomWidgetOne,CustomWidgetTwoandCustomWidgetThree, 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) QList<QDesignerCustomWidgetInterface*> customWidgets() override # 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): super().__init__(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 Widgets Designer can access and construct the custom widgets. Without this macro, there is no way for Qt Widgets Designer to use them.
See also
QDesignerCustomWidgetInterfaceCreating-Custom-Widgets-for-Qt-Widgets-DesignerSynopsis¶
Virtual methods¶
def
customWidgets()
Note
This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE
- abstract customWidgets()¶
- Return type:
.list of QDesignerCustomWidgetInterface
Returns a list of interfaces to the collection’s custom widgets.