aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/quick/qquickitem2/data/focusableItemReparentedToLoadedComponent.qml
blob: a690c4243b21f43778abd544705efcdf0295dede (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import QtQuick 2.12

Item {
    width: 240; height: 240
    Loader {
        id: loader
        sourceComponent: surfaceParent
        anchors.fill: parent

        onStatusChanged: {
            if (status === Loader.Ready) {
                holder.create()
                holder.item.parent = item
            } else if (status === Loader.Null){
                holder.item.parent = null
            }
        }
    }

    property var holder: QtObject {
        property bool created: false
        function create()
        {
            if (!created)
                surfaceComponent.createObject(item)
            created = true
        }

        property Item item: Item {
            anchors.fill: parent
            Component {
                id: surfaceComponent
                Item {
                    anchors.fill: parent
                    TextInput {
                        width: parent.width
                        font.pixelSize: 40
                        text: "focus me"
                    }
                }
            }
        }
    }

    Component {
        id: surfaceParent
        Rectangle {
            anchors.fill: parent
        }
    }
}