2018年5月8日

ScriptAction

モジュール

QtQuick 2.0

クラス継承

QQuickScriptAction → QQuickAbstractAnimation (internal) → QObject

プロパティー

script: QQmlScriptString = QQmlScriptString()
scriptName: QString = ""

説明


プロパティーの説明

script: QQmlScriptString

scriptName: QString

参考情報

2018年5月7日

DelegateModelGroup

モジュール

QtQml.Models 2.1

クラス継承

QQmlDelegateModelGroup → QObject

プロパティー

count: int = 0 readonly
name: QString = ""
includeByDefault: bool = false

シグナル

changed(QQmlV4Handle removed, QQmlV4Handle inserted)
countChanged()
defaultIncludeChanged()
nameChanged()

メソッド

QQmlV4Handle get(int index)

スロット

void addGroups(QQmlV4Function*)
void create(QQmlV4Function*)
void insert(QQmlV4Function*)
void move(QQmlV4Function*)
void resolve(QQmlV4Function*)
void remove(QQmlV4Function*)
void removeGroups(QQmlV4Function*)
void setGroups(QQmlV4Function*)

説明


プロパティーの説明

count: int

name: QString

includeByDefault: bool

シグナルの説明

changed(QQmlV4Handle removed, QQmlV4Handle inserted)


defaultIncludeChanged()

includeByDefault プロパティーの変更通知シグナル。

メソッドの説明

QQmlV4Handle get(int index)

スロットの説明

void addGroups(QQmlV4Function*)

void create(QQmlV4Function*)

void insert(QQmlV4Function*)

void move(QQmlV4Function*)

void resolve(QQmlV4Function*)

void remove(QQmlV4Function*)

void removeGroups(QQmlV4Function*)

void setGroups(QQmlV4Function*)

注意


includeByDefault プロパティーの変更通知シグナルが defaultIncludeChanged() となっていて命名規則と異なっている。

参考情報

2018年5月6日

ParentChange

モジュール

QtQuick 2.0

クラス継承

QQuickParentChange → QQuickStateOperation (internal) → QObject

プロパティー

target: Item = null
parent: Item = null
x: QQmlScriptString = ""
y: QQmlScriptString = ""
width: QQmlScriptString = ""
height: QQmlScriptString = ""
scale: QQmlScriptString = ""
rotation: QQmlScriptString = ""

説明


target に指定したビジュアルオブジェクトの parent を変更する。

x、y、width、height、scale、rotation で指定しないものがあるとき、parent を変更するビジュアルオブジェクトのそれらの値は見掛けをそのままにするような parent 変更先ビジュアルオブジェクト座標系での値に変更される。つまり、x と y の座標値は parent 変更先ビジュアルオブジェクトから見た座標値になり、スケールは逆数に、角度は逆向きになって、parent を変更する前の見掛けを保つように変更される。

x、y、width、height、scale、rotation のいずれかあるいは複数に parent 変更先ビジュアルオブジェクトでのプロパティー値を設定すると ParentAnimation でアニメーション効果を付けられる。

サンプルコード switchparent.qml を参照。

プロパティーの説明

target: Item

parent を変更するビジュアルオブジェクト。

parent: Item

parent 変更先ビジュアルオブジェクト。

x: QQmlScriptString

parent 変更先ビジュアルオブジェクトでの x 座標値を指定する。

y: QQmlScriptString

parent 変更先ビジュアルオブジェクトでの y 座標値を指定する。

width: QQmlScriptString

parent 変更後の幅を指定する。

height: QQmlScriptString

parent 変更後の高さを指定する。

scale: QQmlScriptString

parent 変更後のスケールを指定する。

rotation: QQmlScriptString

parent 変更後の角度を指定する。

問題


兄弟関係にある複数ビジュアルオブジェクトの parent を変更しようとすると正しく動作しない場合がある。

参考情報

ParentAnimation

モジュール

QtQuick 2.0

クラス継承

QQuickParentAnimation →  QQuickAnimationGroup (internal) → QQuickAbstractAnimation (internal) → QObject

プロパティー

target: Item = null
newParent: Item = null
via: Item = null

シグナル

targetChanged()
newParentChanged()
viaChanged()

説明


サンプルコード switchparent.qml を参照。


プロパティーの説明

target: Item

newParent: Item

via: Item

parent 変更先のビジュアルオブジェクトが parent 変更元のビジュアルオブジェクトよりも描画順序が先の場合や parent 変更先と変更元のいずれかのビジュアルオブジェクトの clip が true に設定されている場合に、clip が false に設定されているビジュアルオブジェクトを指定して parent を変えるビジュアルオブジェクトが隠れないようにする。

問題


ParentAnimation のリファレンスには親ビジュアルオブジェクトの clip が true のときの via 使用について書かれているがビジュアルオブジェクトの描画順序のために via が必要なことが書かれていない。

参考情報

2018年5月5日

switchparent.qml

switchparent.qml:

import QtQuick 2.10
import QtQuick.Window 2.10
import QtQuick.Layouts 1.3

Window {
    id: window

    visible: true

    minimumWidth: 300
    minimumHeight: 300

    RowLayout {
        id: topLayout

        anchors.fill: parent
        anchors.margins: spacing

        Rectangle {
            id: leftRect

            Layout.fillWidth: true
            Layout.fillHeight: true

            objectName: "leftRect"
            color: "red"

            Rectangle {
                id: innerRect

                x: 10; y: 10
                width: (minimumWidth - 3*topLayout.spacing)/2 - 2*10
                height: width

                color: "blue"

                Text {
                    anchors.centerIn: parent

                    text: "%1\n%2, %3\n%4x%5".arg(innerRect.parent.objectName)
                                             .arg(parent.x).arg(parent.y)
                                             .arg(parent.width).arg(parent.height)
                    color: "white"
                }
            }
        }

        Rectangle {
            id: rightRect

            Layout.fillWidth: true
            Layout.fillHeight: true

            objectName: "rightRect"
            color: "green"
        }
    }

    contentItem.states: State {
        name: "switchToRight"

        ParentChange {
            target: innerRect
            parent: rightRect
            x: rightRect.width - innerRect.width - 10
            y: rightRect.height - innerRect.height - 10
        }

        PropertyChanges {
            target: innerRect
            color: "darkblue"
        }
    }

    contentItem.transitions: Transition {
        ParentAnimation {
            via: contentItem

            NumberAnimation {
                properties: "x, y"
                duration: 3000
            }

            ColorAnimation {
                duration: 3000
            }
        }
    }

    MouseArea {
        anchors.fill: parent

        onClicked: {
            if (contentItem.state === "") {
                contentItem.state = "switchToRight";
            } else {
                contentItem.state = "";
            }
        }
    }
}
ウィンドウをクリックすると青い Rectangle の parent を右側の Rectangle に変更し右下に配置する。もう一度クリックすると parent を元に戻している。ParentAnimation 内の 2 つのアニメーションは並列に動作する。ParentAnimation で via を指定しないと青い Rectangle が右側から左側に移動するときに右側の Rectangle の裏に隠れてしまう。これはアニメーション開始時に青い Rectangle の parent が左側の Rectangle に変わることと、左側の Rectangle の parent 設定が右側の Rectangle の parent 設定よりも先に行われているので左側の Rectangle が右側の Rectangle の下に描画されるためである。