Unable to use Keys.onPressed on two qml files
Solved
QML and Qt Quick
-
Hello QT,
I and my friend are unable to use Keys.onPressed on two QML files.
Actually i wanted to create a QML file that will take up all the user input and then will call respective QML files, but i am unable to figure out on how to do.
Even when i used Keys.onPressed on two qml file , i am getting input for only one file only. Please give me a rough code idea on how to take up Keys.onPressed to two QMl files.Qml1 - Take Keyboard input
Qml2 - Take Input of Keyboard from QMl1
Qml3 - Take input of Keyboard from Qml 1Thanks and Regards,
Arya Kumar -
untitled26.qml
Window { visible: true width: 640 height: 480 title: qsTr("Hello World") KeyInput{} Rectangle { id: rect1 width: 64 height: 48 anchors.centerIn: parent color: "RED" } Rect2 { } }
Rect2.qml
import QtQuick 2.0 Item { Rectangle { id: rect2 width: 64 height: 48 color: "blue" } }
KeyInput.qml
import QtQuick 2.0 //import "Rect2" Item { anchors.fill: parent focus: true Keys.onPressed: { if (event.key === Qt.Key_Right) { console.log("move left"); event.accepted = true; rect1.color = "BLUE" rect2.color = "BLUE" /*unable to change rect2*/ } if (event.key === Qt.Key_Left) { console.log("move right"); event.accepted = true; rect1.color = "RED" rect2.color = "RED" /*unable to change rect2*/ } } }
I am unable to change rect2 color
-
OK i figured out , i need to create property in my QMl file and then access it from other file