Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Unable to use Keys.onPressed on two qml files

Unable to use Keys.onPressed on two qml files

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 1 Posters 431 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Arya Kumar
    wrote on last edited by
    #1

    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 1

    Thanks and Regards,
    Arya Kumar

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Arya Kumar
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Arya Kumar
        wrote on last edited by
        #3

        OK i figured out , i need to create property in my QMl file and then access it from other file

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved