Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Setting "focus" true in multiple elements

Setting "focus" true in multiple elements

Scheduled Pinned Locked Moved Solved Mobile and Embedded
11 Posts 3 Posters 1.6k Views 2 Watching
  • 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.
  • Q Offline
    Q Offline
    qcoderpro
    wrote on last edited by
    #1

    Hi all,

    How to make both elements work with keys? Now only the first text accepts keys:

    import QtQuick 2.15
    import QtQuick.Window 2.15
    
    Window {
        width: 640
        height: 480
        visible: true
        title: qsTr("Hello World")
    
        Text {
            id: thisLabel
            x: 24;
            anchors.bottom: parent.bottom
            anchors.right: parent.right
    
            property int times: 24
    
            text: "Greetings " + times
    
            font.family: "Ubuntu"
            font.pixelSize: 24
            focus: true
            color: focus?"red":"black"
            Keys.onTabPressed: ++times
        }
    
        Text {
            id: otherLabel
            x: 124;
            anchors.bottom: parent.bottom
    
            property int spacePresses: 0
    
            text: "Space pressed: " + spacePresses + " times"
    
            font.family: "Ubuntu"
            font.pixelSize: 24
    
            focus: true
    
            Keys.onEscapePressed: otherLabel.text = ' '
            Keys.onSpacePressed: increment()
    
            function increment() {
                ++spacePresses
            }
        }
    }
    

    A side question connected to this category (Mobile and Embedded). Where/How to start programming QML (QtQucik) on embedded devices, please?

    jsulmJ 1 Reply Last reply
    0
    • Q qcoderpro

      Hi all,

      How to make both elements work with keys? Now only the first text accepts keys:

      import QtQuick 2.15
      import QtQuick.Window 2.15
      
      Window {
          width: 640
          height: 480
          visible: true
          title: qsTr("Hello World")
      
          Text {
              id: thisLabel
              x: 24;
              anchors.bottom: parent.bottom
              anchors.right: parent.right
      
              property int times: 24
      
              text: "Greetings " + times
      
              font.family: "Ubuntu"
              font.pixelSize: 24
              focus: true
              color: focus?"red":"black"
              Keys.onTabPressed: ++times
          }
      
          Text {
              id: otherLabel
              x: 124;
              anchors.bottom: parent.bottom
      
              property int spacePresses: 0
      
              text: "Space pressed: " + spacePresses + " times"
      
              font.family: "Ubuntu"
              font.pixelSize: 24
      
              focus: true
      
              Keys.onEscapePressed: otherLabel.text = ' '
              Keys.onSpacePressed: increment()
      
              function increment() {
                  ++spacePresses
              }
          }
      }
      

      A side question connected to this category (Mobile and Embedded). Where/How to start programming QML (QtQucik) on embedded devices, please?

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @qcoderpro said in Setting "focus" true in multiple elements:

      How to make both elements work with keys?

      Do you mean you want both text items to get the input at the same time? Only the one with focus gets the input. You will have to write code to also pass the input to the item without focus I think.

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      Q 1 Reply Last reply
      2
      • jsulmJ jsulm

        @qcoderpro said in Setting "focus" true in multiple elements:

        How to make both elements work with keys?

        Do you mean you want both text items to get the input at the same time? Only the one with focus gets the input. You will have to write code to also pass the input to the item without focus I think.

        Q Offline
        Q Offline
        qcoderpro
        wrote on last edited by
        #3

        @jsulm

        Only the one with focus gets the input.

        Both have focus: true!

        You will have to write code to also pass the input to the item without focus I think.

        You mean this:

        Window {
            width: 640
            height: 480
            visible: true
            title: qsTr("Hello World")
        
            Text {
                id: thisLabel
                x: 24;
                anchors.bottom: parent.bottom
                anchors.right: parent.right
        
                property int times: 24
        
                text: "Greetings " + times
        
                font.family: "Ubuntu"
                font.pixelSize: 24
                color: "red"
                Keys.onTabPressed: ++times
            }
        
            Text {
                id: otherLabel
                x: 124;
                anchors.bottom: parent.bottom
        
                property int spacePresses: 0
        
                text: "Space pressed: " + spacePresses + " times"
        
                font.family: "Ubuntu"
                font.pixelSize: 24
        
                focus: true
        
                Keys.onEscapePressed: otherLabel.text = ' '
                Keys.onSpacePressed: increment()
        
                function increment() {
                    ++spacePresses
                    ++thisLabel.times
                }
            }
        }
        
        jsulmJ ODБOïO 2 Replies Last reply
        0
        • Q qcoderpro

          @jsulm

          Only the one with focus gets the input.

          Both have focus: true!

          You will have to write code to also pass the input to the item without focus I think.

          You mean this:

          Window {
              width: 640
              height: 480
              visible: true
              title: qsTr("Hello World")
          
              Text {
                  id: thisLabel
                  x: 24;
                  anchors.bottom: parent.bottom
                  anchors.right: parent.right
          
                  property int times: 24
          
                  text: "Greetings " + times
          
                  font.family: "Ubuntu"
                  font.pixelSize: 24
                  color: "red"
                  Keys.onTabPressed: ++times
              }
          
              Text {
                  id: otherLabel
                  x: 124;
                  anchors.bottom: parent.bottom
          
                  property int spacePresses: 0
          
                  text: "Space pressed: " + spacePresses + " times"
          
                  font.family: "Ubuntu"
                  font.pixelSize: 24
          
                  focus: true
          
                  Keys.onEscapePressed: otherLabel.text = ' '
                  Keys.onSpacePressed: increment()
          
                  function increment() {
                      ++spacePresses
                      ++thisLabel.times
                  }
              }
          }
          
          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @qcoderpro said in Setting "focus" true in multiple elements:

          Both have focus: true!

          That doesn't mean that both HAVE focus. This is not how UI works. Only one UI element can have focus at a given point in time...

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          3
          • Q qcoderpro

            @jsulm

            Only the one with focus gets the input.

            Both have focus: true!

            You will have to write code to also pass the input to the item without focus I think.

            You mean this:

            Window {
                width: 640
                height: 480
                visible: true
                title: qsTr("Hello World")
            
                Text {
                    id: thisLabel
                    x: 24;
                    anchors.bottom: parent.bottom
                    anchors.right: parent.right
            
                    property int times: 24
            
                    text: "Greetings " + times
            
                    font.family: "Ubuntu"
                    font.pixelSize: 24
                    color: "red"
                    Keys.onTabPressed: ++times
                }
            
                Text {
                    id: otherLabel
                    x: 124;
                    anchors.bottom: parent.bottom
            
                    property int spacePresses: 0
            
                    text: "Space pressed: " + spacePresses + " times"
            
                    font.family: "Ubuntu"
                    font.pixelSize: 24
            
                    focus: true
            
                    Keys.onEscapePressed: otherLabel.text = ' '
                    Keys.onSpacePressed: increment()
            
                    function increment() {
                        ++spacePresses
                        ++thisLabel.times
                    }
                }
            }
            
            ODБOïO Offline
            ODБOïO Offline
            ODБOï
            wrote on last edited by
            #5

            @qcoderpro
            focus handling https://doc.qt.io/qt-5/qtquick-input-focus.html

            @qcoderpro said in Setting "focus" true in multiple elements:

            A side question connected to this category (Mobile and Embedded). Where/How to start programming QML (QtQucik) on embedded devices, please?

            Nothing special to do about that, Qt is cross-platform, just learn QtQuick/QML and you will be able to write applications for embedded targets.
            here is a good ressource https://qmlbook.github.io/

            1 Reply Last reply
            1
            • Q Offline
              Q Offline
              qcoderpro
              wrote on last edited by qcoderpro
              #6

              @LeLev

              just learn QtQuick/QML and you will be able to write applications for embedded targets.

              OK. So if I want to run the simple project above on an imbedded system the steps are as follow:

              1- First I need to know the OS the embedded system is using.
              2- Compile the program for that OS and run the resulting executive file on the embedded device OS

              Right?

              ODБOïO 1 Reply Last reply
              0
              • Q qcoderpro

                @LeLev

                just learn QtQuick/QML and you will be able to write applications for embedded targets.

                OK. So if I want to run the simple project above on an imbedded system the steps are as follow:

                1- First I need to know the OS the embedded system is using.
                2- Compile the program for that OS and run the resulting executive file on the embedded device OS

                Right?

                ODБOïO Offline
                ODБOïO Offline
                ODБOï
                wrote on last edited by
                #7

                @qcoderpro that is correct

                Q 1 Reply Last reply
                1
                • ODБOïO ODБOï

                  @qcoderpro that is correct

                  Q Offline
                  Q Offline
                  qcoderpro
                  wrote on last edited by
                  #8

                  @LeLev

                  One last question that may clarify what I'm thinking about right now.

                  Apparently many of the embedded devices are running a flavor of Linux. Let's say my device is alike. Therefore we don't compile the project on that device, because it may or may not have a compiler accompanying its OS (here Linux). We, instead, compile our QML project using the compiler within the Qt Creator IDE on our desktop machine, which makes the things much easier, and afterwards copy the executable file created, specific for that OS, and just transfer it onto the device and simply run it.

                  Are my assumptions right?

                  jsulmJ 1 Reply Last reply
                  0
                  • Q qcoderpro

                    @LeLev

                    One last question that may clarify what I'm thinking about right now.

                    Apparently many of the embedded devices are running a flavor of Linux. Let's say my device is alike. Therefore we don't compile the project on that device, because it may or may not have a compiler accompanying its OS (here Linux). We, instead, compile our QML project using the compiler within the Qt Creator IDE on our desktop machine, which makes the things much easier, and afterwards copy the executable file created, specific for that OS, and just transfer it onto the device and simply run it.

                    Are my assumptions right?

                    jsulmJ Offline
                    jsulmJ Offline
                    jsulm
                    Lifetime Qt Champion
                    wrote on last edited by jsulm
                    #9

                    @qcoderpro said in Setting "focus" true in multiple elements:

                    compiler within the Qt Creator IDE

                    QtCreator does not have any compilers. It uses compilers configured in the Kit. On Linux GCC, on Windows MSVC++ or MinGW and on MacOS clang.
                    You need a cross-compiler generating binaries for your target device. For example if your device has an ARM CPU you need a compiler running on your device but generating binaries running on ARM CPU. You can't use the compiler for your host system. You also need a sysroot for your device. A sysroot contains libraries and headers from your target device and is needed to be able to compile and link your app. Often manufacturers provide a SDK containing all this: do you have a SDK?

                    https://forum.qt.io/topic/113070/qt-code-of-conduct

                    Q 1 Reply Last reply
                    4
                    • jsulmJ jsulm

                      @qcoderpro said in Setting "focus" true in multiple elements:

                      compiler within the Qt Creator IDE

                      QtCreator does not have any compilers. It uses compilers configured in the Kit. On Linux GCC, on Windows MSVC++ or MinGW and on MacOS clang.
                      You need a cross-compiler generating binaries for your target device. For example if your device has an ARM CPU you need a compiler running on your device but generating binaries running on ARM CPU. You can't use the compiler for your host system. You also need a sysroot for your device. A sysroot contains libraries and headers from your target device and is needed to be able to compile and link your app. Often manufacturers provide a SDK containing all this: do you have a SDK?

                      Q Offline
                      Q Offline
                      qcoderpro
                      wrote on last edited by
                      #10

                      @jsulm

                      You need a cross-compiler generating binaries for your target device.
                      For example if your device has an ARM CPU you need a compiler running on your device but generating binaries running on ARM CPU. You can't use the compiler for your host system. You also need a sysroot for your device. A sysroot contains libraries and headers from your target device and is needed to be able to compile and link your app. Often manufacturers provide a SDK containing all this: do you have a SDK?

                      I don't really have a device for embedded programming. I just wanted to know the process, the steps you talked about above. But that shows that embedded programming is not merely programming. There are other stuff to know to be able to run/install the program you've already written on your computer on your device. I need to know that process.

                      jsulmJ 1 Reply Last reply
                      0
                      • Q qcoderpro

                        @jsulm

                        You need a cross-compiler generating binaries for your target device.
                        For example if your device has an ARM CPU you need a compiler running on your device but generating binaries running on ARM CPU. You can't use the compiler for your host system. You also need a sysroot for your device. A sysroot contains libraries and headers from your target device and is needed to be able to compile and link your app. Often manufacturers provide a SDK containing all this: do you have a SDK?

                        I don't really have a device for embedded programming. I just wanted to know the process, the steps you talked about above. But that shows that embedded programming is not merely programming. There are other stuff to know to be able to run/install the program you've already written on your computer on your device. I need to know that process.

                        jsulmJ Offline
                        jsulmJ Offline
                        jsulm
                        Lifetime Qt Champion
                        wrote on last edited by
                        #11

                        @qcoderpro said in Setting "focus" true in multiple elements:

                        I need to know that process

                        The process is called "cross compiling".
                        You can for example tale a look at this: https://stackoverflow.com/questions/897289/what-is-cross-compilation

                        https://forum.qt.io/topic/113070/qt-code-of-conduct

                        1 Reply Last reply
                        3

                        • Login

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