[solved] Z-order in dynamically created object
-
I want to the red rectangle has higher Z value than blue one, but it does not seems it's working between two objects in different files.
main.qml
@import QtQuick 2.2
import QtQuick.Controls 1.1ApplicationWindow {
id: root
visible: true
width: 640
height: 480Rectangle { color: "red" height: 100 width: 100 z: 1 Component.onCompleted: { var component = Qt.createComponent("rect.qml") var object = component.createObject(root) } }}@
rect.qml
@import QtQuick 2.0Rectangle {
y: 50
width: 100
height: 100
color: "blue"
z: 0
}@Thank you
-
You are aware you do not need Qt.createComponent() in this case, right?
Anyway, to answer. Try this:
@
Component.onCompleted: {
var component = Qt.createComponent("rect.qml")
var object = component.createObject(root)
object.z = 0;
}
@ -
Hi,
If you use Item instead of ApplicationWindow it works as expected. But wondering why it doesn't with ApplicationWindow !!!
-
Are you using QQmlApplicationEngine to load the QML file ?
-
In order to show your QML when switching away from ApplicationWindow, you can use QQuickView class.
-
Also another observation, keeping ApplicationWindow if you set the z value of Rect to negative also works as expected.