QDesignerCustomWidgetCollectionInterface Class

QDesignerCustomWidgetCollectionInterface クラスを使用すると、複数のカスタムウィジェットを 1 つのライブラリに含めることができます。詳細...

ヘッダー #include <QDesignerCustomWidgetCollectionInterface>
CMake: find_package(Qt6 REQUIRED COMPONENTS Designer)
target_link_libraries(mytarget PRIVATE Qt6::Designer)
qmake: QT += designer

パブリック関数

virtual ~QDesignerCustomWidgetCollectionInterface()
virtual QList<QDesignerCustomWidgetInterface *> customWidgets() const = 0

詳細説明

カスタムウィジェットプラグインを実装する場合、別のライブラリとして構築します。複数のカスタムウィジェットプラグインを同じライブラリに含める場合は、さらにQDesinarCustomWidgetCollectionInterfaceをサブクラス化する必要があります。

QDesignerCustomWidgetCollectionInterfaceには、コレクションのQDesignerCustomWidgetInterface オブジェクトのリストを返す単一の関数があります。例えば、いくつかのカスタムウィジェットCustomWidgetOneCustomWidgetTwoCustomWidgetThree がある場合、クラス定義は次のようになります:

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

#include <QtDesigner/qtdesigner.h>
#include <QtCore/qplugin.h>

class MyCustomWidgets: public QObject, public QDesignerCustomWidgetCollectionInterface
{
    Q_OBJECT
    Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QDesignerCustomWidgetCollectionInterface")
    Q_INTERFACES(QDesignerCustomWidgetCollectionInterface)

public:
    MyCustomWidgets(QObject *parent = 0);

    QList<QDesignerCustomWidgetInterface*> customWidgets() const override;

private:
    QList<QDesignerCustomWidgetInterface*> widgets;
};

クラス・コンストラクタでは、customWidgets() 関数で返すリストに、カスタム・ウィジェットのインタフェースを追加します:

MyCustomWidgets::MyCustomWidgets(QObject *parent)
        : QObject(parent)
{
    widgets.append(new CustomWidgetOneInterface(this));
    widgets.append(new CustomWidgetTwoInterface(this));
    widgets.append(new CustomWidgetThreeInterface(this));
}

QList<QDesignerCustomWidgetInterface*> MyCustomWidgets::customWidgets() const
{
    return widgets;
}

Q_PLUGIN_METADATA() マクロを使用して各カスタム・ウィジェット・プラグインをエクスポートする代わりに、コレクション全体をエクスポートすることに注意してください。Q_PLUGIN_METADATA() マクロは、Qt Widgets Designer がカスタム ウィジェットにアクセスして構築できるようにします。このマクロを使用しないと、Qt Widgets Designer はカスタム ウィジェットを使用できません。

QDesignerCustomWidgetInterface および Qt Widgets Designer 用カスタム ウィジェットの作成も参照してください

メンバ関数のドキュメント

[virtual constexpr noexcept] QDesignerCustomWidgetCollectionInterface::~QDesignerCustomWidgetCollectionInterface()

カスタムウィジェットコレクションインタフェースを破棄します。

[pure virtual] QList<QDesignerCustomWidgetInterface *> QDesignerCustomWidgetCollectionInterface::customWidgets() const

コレクションのカスタムウィジェットのインターフェースのリストを返します。

© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.