PySide6.QtDesigner.QDesignerCustomWidgetCollectionInterface

class QDesignerCustomWidgetCollectionInterface

QDesignerCustomWidgetCollectionInterface 类允许您在一个库中包含多个自定义小部件。更多

概要

虚拟方法

注意

本文档可能包含从C++自动翻译到Python的代码片段。我们始终欢迎对代码片段翻译的贡献。如果您发现翻译问题,您也可以通过在我们的https:/bugreports.qt.io/projects/PYSIDE上创建工单来告知我们。

详细描述

警告

本节包含从C++自动翻译到Python的代码片段,可能包含错误。

在实现自定义小部件插件时,您将其构建为一个单独的库。如果您想在同一库中包含多个自定义小部件插件,您还必须子类化 QDesignerCustomWidgetCollectionInterface

QDesignerCustomWidgetCollectionInterface 包含一个单一的函数,返回集合的 QDesignerCustomWidgetInterface 对象列表。例如,如果你有几个自定义小部件 CustomWidgetOne, CustomWidgetTwoCustomWidgetThree,类定义可能如下所示:

#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()

在类构造函数中,您将自定义小部件的接口添加到您在customWidgets()函数中返回的列表中:

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

请注意,不是使用Q_PLUGIN_METADATA()宏导出每个自定义小部件插件,而是导出整个集合。Q_PLUGIN_METADATA()宏确保Qt Widgets Designer可以访问和构造自定义小部件。如果没有这个宏,Qt Widgets Designer将无法使用它们。

另请参阅

QDesignerCustomWidgetInterface 为Qt Widgets Designer创建自定义小部件

abstract customWidgets()
Return type:

QDesignerCustomWidgetInterface的列表

返回集合的自定义小部件的接口列表。