を継承すると奇妙な動作に気づきましたFlickable
。
私は2つのファイルを持っていComp.qml
ますmain.qml
. Comp
オブジェクトの子はすべてFlickable
underの子になるという考え方ですComp
。を使用して内容をデフォルトにしました
default property alias contents: flickable.children
しかし、結果は奇妙であることが判明しました。
Comp.qml
Rectangle {
id: comp;
anchors.fill: parent
default property alias contents: flickable.children; // alias a default property
property int contentHeight: comp.height;
Flickable {
id: flickable;
anchors.fill: parent;
contentHeight: comp.contentHeight;
}
}
main.qml
Rectangle {
id: root;
width: 400;
height: 400;
Comp {
contentHeight: 800;
Rectangle { // <-- this rectangle should be a child of Flickable
width: 800;
height: 800;
border.color: "black";
border.width: 5;
Component.onCompleted: console.debug(parent)
}
}
}
フリックが効かない。
すべてを 1 つのファイルに入れようとすると、期待どおりに動作します。
main.qml
Rectangle {
id: root;
width: 400;
height: 400;
Rectangle {
id: comp;
anchors.fill: parent
Flickable {
id: flickable;
anchors.fill: parent;
contentHeight: 800;
Rectangle { // <-- the child component
width: 800;
height: 800;
border.color: "black";
border.width: 5;
}
}
}
}
何か不足していますか?に外部コンポーネントを追加するにはどうすればよいFlickable
ですか?