このページでは

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

詳細な説明

カスタムウィジェットプラグインを実装する際は、それを独立したライブラリとしてビルドします。複数のカスタムウィジェットプラグインを同じライブラリに含めたい場合は、さらに QDesignerCustomWidgetCollectionInterface をサブクラス化する必要があります。

QDesignerCustomWidgetCollectionInterface には、コレクション内の `QDesignerCustomWidgetInterface ` オブジェクトのリストを返す関数が 1 つ含まれています。たとえば、CustomWidgetOne 、CustomWidgetTwo 、CustomWidgetThree という複数のカスタムウィジェットがある場合、クラスの定義は次のようになります:

#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 default] QDesignerCustomWidgetCollectionInterface::~QDesignerCustomWidgetCollectionInterface()

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

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

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

© 2026 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.