2018年3月20日

Item

モジュール

QtQuick 2.11

クラス継承

QQuickItem → QObject

プロパティー

activeFocus: bool = false readonly final
activeFocusOnTab: bool = false final
anchors: QQuickAnchors* = QQuickAnchors(this) readonly final
antialiasing: bool = false
children: list<Item> = [] readonly
childrenRect: rect = Qt.rect(0, 0, 0, 0) readonly final
clip: bool = false
containmentMask: QtObject = null
data: list<QtObject> = [] readonly default
enabled: bool = true
focus: bool = false final
height: real = 0 final
implicitHeight: real = 0
implicitWidth: real = 0
layer: QQuickItemLayer* = QQuickItemLayer(this) readonly final
opacity: real = 1 final
parent: Item = null final
resources: list<QtObject> = [] readonly
rotation: real = 0
scale: real = 1
smooth: bool = true
state: string = ""
states: list<State> = [] readonly
transform: list<Transform> = [] readonly final
transitions: Property<Transition> = [] readonly
transformOrigin: TransformOrigin = Item.Center
transformOriginPoint: point = 中心点 readonly
visible: bool = true final
visibleChildren: list<Item> = [] readonly
width: real = 0 final
x: real = 0 final
y: real = 0 final
z: real = 0 final

baseline: QQuickAnchorLine = QQuickAnchors::BaselineAnchor readonly final
baselineOffset: real = 0
bottom: QQuickAnchorLine = QQuickAnchors::BottomAnchor readonly final
horizontalCenter: QQuickAnchorLine = QQuickAnchors::HCenterAnchor readonly final
left: QQuickAnchorLine = QQuickAnchors::LeftAnchor readonly final
right: QQuickAnchorLine = QQuickAnchors::RightAnchor readonly final
top: QQuickAnchorLine = QQuickAnchors::TopAnchor readonly final
verticalCenter: QQuickAnchorLine = QQuickAnchors::VCenterAnchor readonly final

シグナル

windowChanged(QQuickWindow* window)

activeFocusChanged(bool)
activeFocusOnTabChanged(bool)
antialiasingChanged(bool)
baselineOffsetChanged(real)
childrenChanged()
childrenRectChanged(rect)
clipChanged(bool)
containmentMaskChanged()
enabledChanged()
focusChanged(bool)
implicitHeightChanged()
implicitWidthChanged()
opacityChanged()
parentChanged(Item)
rotationChanged()
scaleChanged()
smoothChanged(bool)
stateChanged(string)
transformOriginChanged(TransformOrigin)
visibleChanged()
visibleChildrenChanged()
xChanged()
yChanged()
zChanged()
widthChanged()
heightChanged()

メソッド

Item childAt(real x, real y)
Item nextItemInFocusChain()
Item nextItemInFocusChain(bool forward)
bool contains(point point)
bool grabToImage(QJSValue callback)
bool grabToImage(QJSValue callback, size targetSize)
void forceActiveFocus()
void forceActiveFocus(Qt::FocusReason reason)
void mapFromGlobal(QQmlV4Function*)
void mapFromItem(QQmlV4Function*)
void mapToGlobal(QQmlV4Function*)
void mapToItem(QQmlV4Function*)

スロット

void update()

列挙

TransformOrigin
    TopLeft
    Top
    TopRight
    Left
    Center
    Right
    BottomLeft
    Bottom
    BottomRight

説明


プロパティーの説明

activeFocus: bool

activeFocusOnTab: bool

anchors: QQuickAnchors*

anchors を参照。

antialiasing: bool

children: list<Item>

childrenRect: rect

clip: bool

containmentMask: QtObject

Q_INVOKABLE QObject::contains(const QPoint& point) が実装されたマスクオブジェクトを設定する。Item.contains() で内部判定に用いられる。

MouseArea のマスク を参照。

data: list<QtObject>

enabled: bool

focus: bool

height: real

implicitHeight: real

implicitWidth: real

layer: QQuickItemLayer*

opacity: real

parent: Item

resources: list<QtObject>

rotation: real

scale: real

smooth: bool

state: string

states: list<State>

transform: list<Transform>

transitions: list<Transition>

transformOrigin: TransformOrigin

transformOriginPoint: point

visible: bool

visibleChildren: list<Item>

width: real

x: real

y: real

z: real


baseline: QQuickAnchorLine

baselineOffset: real

bottom: QQuickAnchorLine

horizontalCenter: QQuickAnchorLine

left: QQuickAnchorLine

right: QQuickAnchorLine

top: QQuickAnchorLine

verticalCenter: QQuickAnchorLine

シグナルの説明


メソッドの説明


スロットの説明


列挙の説明


注意


シグナルの仮引数が型のみで仮引数名が省略されているものはシグナルハンドラーで呼び出される処理に実引数が渡されるプロパティーはない。以下のようにすればシグナルの実引数を受け取れる。
smoothChanged.connect(function(arg) { ... });
QML の signal によるシグナル定義では、仮引数名なしの定義はできない。仮引数名のない シグナルは C++ で実装されている。

問題


Item のリファレンスに top、bottom、left、right、horizontalCenter、verticalCenter、baseline、transformOriginPoint の各プロパティー、windowChanged シグナルが記載されていない。

参考情報

Item QML Type

Repeater

モジュール

QtQuick 2.0

クラス継承

QQuickRepeater → QQuickItemQObject

プロパティー

count: int = 0 readonly
delegate: Component = undefined default
model: QVariant = null

シグナル

void itemAdded(int index, Item item)
void itemRemoved(int index, Item item)

void countChanged()
void delegateChanged()
void modelChanged()

メソッド

Item itemAt(int index)

説明


delegate に設定されたビジュアルコンポーネントのオブジェクトを生成する。ビジュアルコンポーネントのみ生成できる。生成オブジェクトの親 QObject は nullptr になり、parent は Repeater の parent になる。生成したオブジェクトは Repeater が抱えていて itemAt() で参照できる。

生成オブジェクトには読込み専用プロパティー index に生成順が設定される。model が、整数、配列、文字列リスト、オブジェクトリストの場合には読込み専用プロパティー modelData に要素 (モデルが整数の場合には生成順) が設定される。

model に配列を設定した場合に、変更した配列を再設定すると全オブジェクトの破壊と再生成がされてしまう。以下のようにして配列にオブジェクトを入れれば、オブジェクトの破壊と生成をせずに配列要素の変更をオブジェクトに伝えられる。

objectlist.qml:

import QtQuick 2.10
import QtQuick.Window 2.10

Window {
    id: window

    visible: true

    width: 200; height: 200

    Component {
        id: numberDelegate

        QtObject {
            property string name: "John Doe"
        }
    }

    function createPerson(parent, name) {
        return numberDelegate.createObject(parent, { "name": name });
    }

    Column {
        Repeater {
            id: repeater
            model: [
                       createPerson(contentItem, "John Doe"),
                       createPerson(contentItem, "John Doe"),
                       createPerson(contentItem, "John Doe")
                   ]

            Text {
                text: "Name is " + modelData.name
                font.pointSize: 16
            }
        }
    }

    MouseArea {
        anchors.fill: parent

        onClicked: {
            repeater.model[1].name = "JOHN SMITH";
        }
    }
}

プロパティーの説明

count: int

delegate: Component

オブジェクト生成に使われるコンポーネント。Component の id または Component を記述する。Component タイプの記述を省略した場合には暗黙のコンポーネントと呼ばれ自動的にコンポーネントにになる。

model: QVariant

以下のいずれかを設定する。整数を指定した場合にはその数分のオブジェクトが生成され、他の場合には各要素に対してオブジェクトが生成される。
  • 整数
  • 配列
  • 文字列リスト
  • オブジェクトリスト
  • ObjectModel や ListModel、QAbstractItemModel 継承モデルなど
配列を設定した場合に model を参照すると配列がコピーされて返される。配列を設定するときにも配列がコピーされる。QML カスタムプロパティーに配列オブジェクトを設定すると JavaScript の配列オブジェクトの扱いと同じように配列オブジェクトの参照が用いられるが、Repeater の model では配列オブジェクトがコピーされ、JavaScript の配列オブジェクトの扱いと異なっている。

配列を設定し、配列を再設定した場合の等価性判定は、配列オブジェクトが同じかどうかではなく、要素数と各要素が同じかどうかで判定される。こちらも JavaScript の配列オブジェクトの等価性判定と異なっている。

model に ObjectModel を設定した場合には delegate は設定しなくてよい。ObjectModel の要素がビジュアルデリゲートになるので、delegate を設定しても無視される。

シグナルの説明

void itemAdded(int index, Item item)

ビジュアルオブジェクトが追加されたときに送信されるシグナル。index は追加位置で item は追加されたビジュアルオブジェクト。

void itemRemoved(int index, Item item)

ビジュアルオブジェクトを削除しようとするときに送信されるシグナル。index は削除位置で item は削除しようとするビジュアルオブジェクト。シグナルハンドラー onItemRemoved() を抜けた直後にビジュアルオブジェクトが削除される。

メソッドの説明

Item itemAt(int index)

注意


ポジショナーやレイアウトとよく併用されるがビジュアルオブジェクトを生成してその parent を設定しているだけなのでこれらと併用せずに使える。

Repeater は Item を継承しているがポジショナーとレイアウトは Repeater を無視するようになっているので Repeater 自身はポジショナーとレイアウトで配置されない。

model に配列オブジェクトを設定参照したときの動作が Instantiator の model とは異なっている。

問題


Repeater のリファレンスに model に配列オブジェクトを設定参照した場合に参照ではなくコピーされることが書かれていない。

参考情報