QQuickAttachedPropertyPropagator Class

QQuickAttachedPropertyPropagator 클래스는 첨부된 프로퍼티를 전파하는 방법을 제공합니다. 더 보기...

Header: #include <QQuickAttachedPropertyPropagator>
CMake: find_package(Qt6 REQUIRED COMPONENTS QuickControls2)
target_link_libraries(mytarget PRIVATE Qt6::QuickControls2)
qmake: QT += quickcontrols2
이후: Qt 6.5
상속합니다: QObject

공용 함수

QQuickAttachedPropertyPropagator(QObject *parent = nullptr)
virtual ~QQuickAttachedPropertyPropagator()
QList<QQuickAttachedPropertyPropagator *> attachedChildren() const
QQuickAttachedPropertyPropagator *attachedParent() const

보호된 함수

virtual void attachedParentChange(QQuickAttachedPropertyPropagator *newParent, QQuickAttachedPropertyPropagator *oldParent)
void initialize()

상세 설명

QML에서는 프로퍼티와 시그널 핸들러를 객체에 첨부할 수 있습니다. 첨부된 프로퍼티 제공하기에서는 자체 C++ 첨부 유형을 노출하는 방법에 대해 자세히 설명합니다.

QQuickAttachedPropertyPropagator는 fontpalette 전파 방식과 유사하게 부모 객체에서 자식 객체로 첨부 프로퍼티를 전파하는 API를 제공합니다. items , popups, windows 를 통한 전파를 지원합니다.

프로퍼티의 전파가 중요하지 않은 경우에는 C++ 또는 QML 싱글톤을 사용하는 것이 해당 사용 사례에 더 적합하고 QObject 하나만 필요하다는 점에서 더 효율적이므로 대신 사용하는 것이 좋습니다.

QQuickAttachedPropertyPropagator를 사용하려면:

  • 파생하기
  • 생성자에서 initialize()를 호출합니다.
  • 필요에 따라 각 프로퍼티에 대한 설정/상속/전파/리셋 함수를 정의합니다.
  • attachedParentChange()를 다시 구현하여 프로퍼티 상속을 처리합니다.
  • 정적 qmlAttachedProperties 함수를 구현하고 첨부된 프로퍼티 제공에 설명된 대로 QML_ELEMENTQML_ATTACHED 를 사용하여 해당 유형을 첨부된 QML 유형으로 선언합니다.

이를 자세히 설명하는 예제는 Qt Quick Controls - 첨부된 스타일 속성 예제를 참조하십시오.

스타일 지정 Qt Quick Controls도 참조하십시오 .

멤버 함수 문서

[explicit] QQuickAttachedPropertyPropagator::QQuickAttachedPropertyPropagator(QObject *parent = nullptr)

주어진 parent 로 QQuickAttachedPropertyPropagator 를 구축합니다.

parent 은 이 객체의 attached parent 을 찾는 데 사용됩니다.

파생 클래스는 생성자에서 initialize()를 호출해야 합니다.

[virtual noexcept] QQuickAttachedPropertyPropagator::~QQuickAttachedPropertyPropagator()

QQuickAttachedPropertyPropagator 를 파괴합니다.

QList<QQuickAttachedPropertyPropagator *> QQuickAttachedPropertyPropagator::attachedChildren() const

이 함수는 이 첨부된 객체의 첨부된 자식을 반환합니다.

첨부된 자식은 프로퍼티 값을 전파할 때 사용됩니다:

void MyStyle::propagateTheme()
{
    const auto styles = attachedChildren();
    for (QQuickAttachedPropertyPropagator *child : styles) {
        MyStyle *myStyle = qobject_cast<MyStyle *>(child);
        if (myStyle)
            myStyle->inheritTheme(m_theme);
    }
}

QQuickAttachedPropertyPropagator *QQuickAttachedPropertyPropagator::attachedParent() const

이 함수는 이 첨부된 객체의 첨부된 부모를 반환합니다.

첨부된 부모는 프로퍼티 값을 상속할 때 사용됩니다:

void MyStyle::resetTheme()
{
    if (!m_explicitTheme)
        return;

    m_explicitTheme = false;
    MyStyle *myStyle = qobject_cast<MyStyle *>(attachedParent());
    inheritTheme(myStyle ? myStyle->theme() : globalTheme);
}

[virtual protected] void QQuickAttachedPropertyPropagator::attachedParentChange(QQuickAttachedPropertyPropagator *newParent, QQuickAttachedPropertyPropagator *oldParent)

이 함수는 이 QQuickAttachedPropertyPropagator 의 첨부된 부모가 oldParent 에서 newParent 로 변경될 때마다 호출됩니다.

서브클래스는 이 함수를 다시 구현하여 newParent 에서 첨부된 프로퍼티를 상속해야 합니다.

void MyStyle::attachedParentChange(QQuickAttachedPropertyPropagator *newParent, QQuickAttachedPropertyPropagator *oldParent)
{
    Q_UNUSED(oldParent);
    MyStyle *attachedParentStyle = qobject_cast<MyStyle *>(newParent);
    if (attachedParentStyle) {
        inheritTheme(attachedParentStyle->theme());
        // Do any other inheriting here...
    }
}

[protected] void QQuickAttachedPropertyPropagator::initialize()

이 첨부된 객체에 대한 첨부된 부모를 찾아 설정한 다음, 그 자식에 대해서도 동일한 작업을 수행합니다. 전파가 작동하려면 첨부된 객체를 생성할 때 이 함수를 호출해야 합니다.

이 함수를 호출하기 전에 전역/기본값을 읽어두면 유용할 수 있습니다. 예를 들어 Imagine 스타일은 initialize() 을 호출하기 전에 정적 "globalsInitialized" 플래그를 확인하여 QSettings 에서 기본값을 읽어야 하는지 확인합니다. 해당 파일의 값은 명시적으로 설정되지 않은 모든 첨부 속성 값의 기초를 형성합니다.

MyStyle::MyStyle(QObject *parent)
    : QQuickAttachedPropertyPropagator(parent)
    , m_theme(globalTheme)
{
    // A static function could be called here that reads globalTheme from a
    // settings file once at startup. That value would override the global
    // value. This is similar to what the Imagine and Material styles do, for
    // example.

    initialize();
}

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