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. What is focus in qml?
Forum Updated to NodeBB v4.3 + New Features

What is focus in qml?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
6 Posts 2 Posters 1.9k 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.
  • J Offline
    J Offline
    JennyAug13
    wrote on last edited by
    #1

    Hello , I am a beginner in qml, and may i know the focus term. I have a simple example here:

    import QtQuick 2.6
    import QtQuick.Window 2.2
    Window {
    visible: true
    width: 640
    height: 480
    Rectangle{
    width: 50;height: 50
    color: "red"
    focus: true
    anchors.centerIn: parent
    }
    Rectangle{
    width: 50; height: 50
    color: "blue"
    anchors.centerIn: parent
    }
    }
    Though i set the focus to red rectangle, i can see blue rectangle when i run this.
    Here are two overlapping rectangles and I would like to do it as: when user clicks on the window, the focus should change to red rectangle and see red rectangle. It would be nice someone helps in this simple example.

    1 Reply Last reply
    0
    • I Offline
      I Offline
      Ilja
      wrote on last edited by
      #2

      The "focus" property refers to Keyboard focus (http://doc.qt.io/qt-5/qtquick-input-focus.html).

      What happens in your example is that the red rectangle is painted and the blue rectangle is then painted on top of that.

      What you can do is use a MouseArea to react to the mouse click and then toggle the "visible" property of the rectangles in the onClick handler.

      J 1 Reply Last reply
      2
      • I Ilja

        The "focus" property refers to Keyboard focus (http://doc.qt.io/qt-5/qtquick-input-focus.html).

        What happens in your example is that the red rectangle is painted and the blue rectangle is then painted on top of that.

        What you can do is use a MouseArea to react to the mouse click and then toggle the "visible" property of the rectangles in the onClick handler.

        J Offline
        J Offline
        JennyAug13
        wrote on last edited by
        #3

        @Ilja Cant i do anything using focus property?

        1 Reply Last reply
        0
        • I Offline
          I Offline
          Ilja
          wrote on last edited by
          #4

          @JennyAug13 You can, but it is not used for showing or not showing GUI elements. The focus property is used for capturing keyboard input focus.

          1 Reply Last reply
          1
          • J Offline
            J Offline
            JennyAug13
            wrote on last edited by
            #5

            Is that possible for mouse press or drag input status also?

            1 Reply Last reply
            0
            • I Offline
              I Offline
              Ilja
              wrote on last edited by
              #6

              @JennyAug13 As I mentioned earlier, you need a MouseArea to detect mouse clicks. See http://doc.qt.io/qt-5/qml-qtquick-mousearea.html

              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