QDesignerCustomWidgetInterface Class

QDesignerCustomWidgetInterface 클래스를 사용하면 Qt Widgets Designer 사용자 지정 위젯에 액세스하고 구성할 수 있습니다. 더 보기...

헤더: #include <QDesignerCustomWidgetInterface>
CMake: find_package(Qt6 REQUIRED COMPONENTS Designer)
target_link_libraries(mytarget PRIVATE Qt6::Designer)
qmake: QT += designer

공용 함수

virtual ~QDesignerCustomWidgetInterface()
virtual QString codeTemplate() const
virtual QWidget *createWidget(QWidget *parent) = 0
virtual QString domXml() const
virtual QString group() const = 0
virtual QIcon icon() const = 0
virtual QString includeFile() const = 0
virtual void initialize(QDesignerFormEditorInterface *formEditor)
virtual bool isContainer() const = 0
virtual bool isInitialized() const
virtual QString name() const = 0
virtual QString toolTip() const = 0
virtual QString whatsThis() const = 0

매크로

상세 설명

QDesignerCustomWidgetInterface는 인터페이스를 가진 사용자 정의 위젯을 제공합니다. 이 클래스에는 클래스 이름 및 헤더 파일 이름과 같은 위젯에 대한 기본 정보를 반환하기 위해 서브 클래싱해야 하는 함수 집합이 포함되어 있습니다. 다른 함수는 플러그인이 로드될 때 초기화하고 Qt Widgets Designer 에서 사용할 사용자 정의 위젯의 인스턴스를 구성하기 위해 구현해야 합니다.

사용자 정의 위젯을 구현할 때 위젯을 Qt Widgets Designer 에 노출하려면 QDesignerCustomWidgetInterface 를 서브클래싱해야 합니다. 예를 들어, 다음은 Qt Widgets Designer 에서 아날로그 시계 사용자 정의 위젯을 사용할 수 있도록 하는 사용자 정의 위젯 플러그인 예제에서 사용되는 플러그인에 대한 선언입니다:

class AnalogClockPlugin : public QObject, public QDesignerCustomWidgetInterface
{
    Q_OBJECT
    Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QDesignerCustomWidgetInterface")
    Q_INTERFACES(QDesignerCustomWidgetInterface)
public:
    explicit AnalogClockPlugin(QObject *parent = nullptr);

    bool isContainer() const override;
    bool isInitialized() const override;
    QIcon icon() const override;
    QString domXml() const override;
    QString group() const override;
    QString includeFile() const override;
    QString name() const override;
    QString toolTip() const override;
    QString whatsThis() const override;
    QWidget *createWidget(QWidget *parent) override;
    void initialize(QDesignerFormEditorInterface *core) override;

private:
    bool initialized = false;
};

클래스 정의에서 이 특정 사용자 정의 위젯에만 해당하는 부분은 클래스 이름뿐입니다. 또한 인터페이스를 구현하고 있으므로 Q_INTERFACES() 매크로를 사용하여 메타 객체 시스템에 해당 인터페이스가 알려지도록 해야 합니다. 이렇게 하면 Qt Widgets Designer 에서 qobject_cast() 함수를 사용하여 QObject 포인터만 사용하여 지원되는 인터페이스를 쿼리할 수 있습니다.

Qt Widgets Designer 은 사용자 정의 위젯 플러그인을 로드한 후 인터페이스의 initialize() 함수를 호출하여 필요한 리소스를 설정할 수 있도록 합니다. 이 함수는 QDesignerFormEditorInterface 매개변수와 함께 호출되어 플러그인에 Qt Widgets Designer 의 모든 API에 대한 게이트웨이를 제공합니다.

Qt Widgets Designer 적절한 부모 위젯을 사용하여 플러그인의 createWidget() 함수를 호출하여 사용자 정의 위젯의 인스턴스를 구성합니다. 플러그인은 지정된 부모 위젯을 사용하여 사용자 정의 위젯의 인스턴스를 구성하고 반환해야 합니다.

Q_PLUGIN_METADATA() 매크로를 사용하여 사용자 정의 위젯 플러그인을 Qt Widgets Designer 로 내보내기. 예를 들어 libcustomwidgetplugin.so (Unix) 또는 libcustomwidget.dll (Windows)라는 라이브러리에 MyCustomWidget 라는 위젯 클래스가 포함되어 있는 경우 플러그인 헤더가 포함된 파일에 다음 줄을 추가하여 내보낼 수 있습니다:

Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QDesignerCustomWidgetInterface")

이 매크로는 Qt Widgets Designer 에서 사용자 정의 위젯에 액세스하고 구성할 수 있도록 합니다. 이 매크로가 없으면 Qt Widgets Designer 에서 사용할 수 있는 방법이 없습니다.

사용자 정의 위젯 플러그인을 구현할 때는 별도의 라이브러리로 빌드합니다. 같은 라이브러리에 여러 사용자 정의 위젯 플러그인을 포함하려면 QDesignerCustomWidgetCollectionInterface 서브클래스를 추가해야 합니다.

경고: 사용자 정의 위젯 플러그인에 QVariant 프로퍼티가 포함된 경우 다음 types 만 지원된다는 점에 유의하세요:

  • QVariant::ByteArray
  • QVariant::Bool
  • QVariant::Color
  • QVariant::커서
  • QVariant::Date
  • QVariant::DateTime
  • QVariant::Double
  • QVariant::Int
  • QVariant::Point
  • QVariant::Rect
  • QVariant::Size
  • QVariant::SizePolicy
  • QVariant::String
  • QVariant::Time
  • QVariant::UInt

QDesignerCustomWidgetInterface 클래스를 사용하는 전체 예제는 사용자 지정 위젯 예제를 참조하십시오. 이 예는 Qt Widgets Designer 에 대한 사용자 지정 위젯 플러그인을 만드는 방법을 보여줍니다.

QDesignerCustomWidgetCollectionInterface Qt Widgets Designer 에 대한 사용자 정의 위젯 만들기참조하십시오 .

멤버 함수 문서

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

사용자 정의 위젯 인터페이스를 삭제합니다.

[virtual] QString QDesignerCustomWidgetInterface::codeTemplate() const

이 기능은 Qt Widgets Designer 에서 향후 사용을 위해 예약한 기능입니다.

[pure virtual] QWidget *QDesignerCustomWidgetInterface::createWidget(QWidget *parent)

지정된 parent 을 사용하여 사용자 정의 위젯의 새 인스턴스를 반환합니다.

[virtual] QString QDesignerCustomWidgetInterface::domXml() const

사용자 지정 위젯의 속성을 설명하는 데 사용되는 XML을 Qt Widgets Designer 로 반환합니다.

[pure virtual] QString QDesignerCustomWidgetInterface::group() const

사용자 정의 위젯이 속한 그룹의 이름을 반환합니다.

[pure virtual] QIcon QDesignerCustomWidgetInterface::icon() const

Qt Widgets Designer 의 위젯 상자에서 사용자 정의 위젯을 나타내는 데 사용되는 아이콘을 반환합니다.

[pure virtual] QString QDesignerCustomWidgetInterface::includeFile() const

사용자 정의 위젯에 대한 코드를 작성할 때 사용하는 포함 파일의 경로를 반환합니다.

[virtual] void QDesignerCustomWidgetInterface::initialize(QDesignerFormEditorInterface *formEditor)

지정된 formEditor 인터페이스에서 사용할 위젯을 초기화합니다.

isInitialized()도 참조하세요 .

[pure virtual] bool QDesignerCustomWidgetInterface::isContainer() const

사용자 정의 위젯을 컨테이너로 사용하려는 경우 참을 반환하고, 그렇지 않으면 거짓을 반환합니다.

대부분의 사용자 정의 위젯은 다른 위젯을 보관하는 데 사용되지 않으므로 이 함수의 구현은 false를 반환하지만 사용자 정의 컨테이너는 Qt Widgets Designer 에서 올바르게 작동하는지 확인하기 위해 true를 반환합니다.

[virtual] bool QDesignerCustomWidgetInterface::isInitialized() const

위젯이 초기화되면 참을 반환하고, 그렇지 않으면 거짓을 반환합니다.

initialize()도 참조하세요 .

[pure virtual] QString QDesignerCustomWidgetInterface::name() const

인터페이스에서 제공한 사용자 정의 위젯의 클래스 이름을 반환합니다.

반환된 이름은 사용자 정의 위젯에 사용된 클래스 이름과 동일해야 합니다.

[pure virtual] QString QDesignerCustomWidgetInterface::toolTip() const

Qt Widgets Designer 에서 사용할 수 있는 위젯에 대한 간단한 설명을 툴팁으로 반환합니다.

[pure virtual] QString QDesignerCustomWidgetInterface::whatsThis() const

위젯에 대한 "이게 뭐예요?" 도움말의 Qt Widgets Designer 에서 사용할 수 있는 위젯에 대한 설명을 반환합니다.

매크로 문서

QDESIGNER_WIDGET_EXPORT

이 매크로는 사용자 정의 위젯을 정의할 때 Qt Widgets Designer 에서 사용할 수 있도록 플러그인에서 올바르게 내보낼 수 있도록 하는 데 사용됩니다.

일부 플랫폼에서는 Qt Widgets Designer 에서 새 위젯을 만드는 데 필요한 심볼이 빌드 시스템에 의해 플러그인에서 제거되어 사용할 수 없게 됩니다. 이 매크로를 사용하면 해당 플랫폼에서 심볼이 유지되며 다른 플랫폼에서는 부작용이 없습니다.

예를 들어 사용자 정의 위젯 플러그인 예제는 다음 선언을 사용하여 사용자 정의 위젯 클래스를 내보냅니다:

class QDESIGNER_WIDGET_EXPORT AnalogClock : public QWidget
{
    Q_OBJECT
    ...
};

Qt Widgets Designer대한 사용자 정의 위젯 만들기를참조하세요 .

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