QQuickAttachedPropertyPropagator Class

QQuickAttachedPropertyPropagator クラスは、アタッチされたプロパティを伝播する方法を提供します。詳細...

ヘッダー #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++アタッチド型を公開する方法について詳しく説明しています。

font palette QQuickAttachedPropertyPropagator は、親オブジェクトから子オブジェクトにアタッチドプロパティを伝搬するためのAPIを提供します。これは、itemspopupswindows を介したプロパゲーションをサポートしています。

QObjectプロパティの伝搬が重要でない場合は、C++QML のシングルトンを使うことをお勧めします。

QQuickAttachedPropertyPropagator を使用するには、次のようにします:

これを詳しく示す例として、Qt Quick Controls - Attached Style Properties Example を参照してください。

スタイリング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()

このアタッチされたオブジェクトのアタッチされた親オブジェクトを検索して設定し、その子オブジェクトにも同じことを行う。伝播させるためには、アタッチドオブジェクトの構築時にこの関数を呼び出す必要があります。

この関数を呼び出す前に、グローバル値やデフォルト値を読み込んでおくと便利です。例えば、initialize() を呼び出す前に、Imagineスタイルは静的な "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.