[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;
}
@ -
Yep, I am, it's just the simplest example.
Your solution doesn't work :-/. -
Hi,
If you use Item instead of ApplicationWindow it works as expected. But wondering why it doesn't with ApplicationWindow !!!
-
I tried to replace ApplicationWindow by Item and then by Rectangle, they build and run without problem, but window even doesn't show up.
My Qt version is 5.2.1 -
Are you using QQmlApplicationEngine to load the QML file ?
-
Yes, I am.
-
In order to show your QML when switching away from ApplicationWindow, you can use QQuickView class.
-
It works.
Thank you -
Also another observation, keeping ApplicationWindow if you set the z value of Rect to negative also works as expected.