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. [Solved] Item placed below gets focus after mouse button was clicked on an item that is above

[Solved] Item placed below gets focus after mouse button was clicked on an item that is above

Scheduled Pinned Locked Moved QML and Qt Quick
12 Posts 6 Posters 4.7k Views 1 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.
  • M Offline
    M Offline
    Milnadar
    wrote on last edited by
    #1

    There is a TextEdit, which receives focus when you click on it with a mouse button, and there is a rectangle for example, which is placed above TextEdit. When i click on the rectangle, TextEdit, which is below also receives focus. Is there any possibility to avoid this?
    For now i found only one solution - it is to create a mouseArea and fill rectangle with it. But i am no sure if it is good solution.
    Or may be there is an ability to stop mouse clicking cast after any condition is executed?
    Thanks.

    1 Reply Last reply
    0
    • T Offline
      T Offline
      thisisbhaskar
      wrote on last edited by
      #2

      [quote author="Milnadar" date="1312762574"]When i click on the rectangle, TextEdit, which is below also receives focus. Is there any possibility to avoid this?
      [/quote]

      This looks like a bug. You should raise a error in JIRA

      1 Reply Last reply
      0
      • EddyE Offline
        EddyE Offline
        Eddy
        wrote on last edited by
        #3

        can you show your code where we can see the structure of your qml file?

        Qt Certified Specialist
        www.edalsolutions.be

        1 Reply Last reply
        0
        • L Offline
          L Offline
          lgeyer
          wrote on last edited by
          #4

          Are you sure? Events should be propagated to their -children- parents if not handled by the -parent- child, shouldn't they?

          1 Reply Last reply
          0
          • G Offline
            G Offline
            giesbert
            wrote on last edited by
            #5

            I'm not deep in QtQuick, but from standard behavior, it is correct.

            I understood, rectangle is placed on top of the edit. But a rectangle is no focus enabled object, unless you explicitly state it (=mouse region).

            In non QtQuick (and also non Qt environment) if an object (window, widget) get's a click and does not handle it, the parent (next layer) get's the click to react on it. As the rectangle does not handle it, it's correct to forward it to the edit field.

            Nokia Certified Qt Specialist.
            Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

            1 Reply Last reply
            0
            • G Offline
              G Offline
              giesbert
              wrote on last edited by
              #6

              [quote author="Lukas Geyer" date="1312802736"]Are you sure? Events should be propagated to their children if not handled by the parent, shouldn't they?[/quote]

              The other direction, handled by the parent if the child does not handle :-)

              Nokia Certified Qt Specialist.
              Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

              1 Reply Last reply
              0
              • M Offline
                M Offline
                Milnadar
                wrote on last edited by
                #7

                Here is an example:
                @Item{
                Rectangle{height: 100; width: 100; color:"red";MouseArea{anchors.fill: parent; onClicked: console.log("hoho") } }
                Rectangle{height: 50; width: 50; color: "green"}
                }
                @
                Green rectangle is above the red one, but still, when clicking on it, mouseArea that is on the red rectangle says "Hoho" )
                Perhaps the reason is that rectangles are sibling?

                1 Reply Last reply
                0
                • L Offline
                  L Offline
                  lgeyer
                  wrote on last edited by
                  #8

                  [quote author="Gerolf" date="1312803323"][quote author="Lukas Geyer" date="1312802736"]Are you sure? Events should be propagated to their children if not handled by the parent, shouldn't they?[/quote]

                  The other direction, handled by the parent if the child does not handle :-)[/quote]

                  Ahmm.. yes. Didn't I say that? ;-)

                  1 Reply Last reply
                  0
                  • R Offline
                    R Offline
                    roopeshchander
                    wrote on last edited by
                    #9

                    When an item doesn't handle an event, it gets propagated to the item below that (in the same (x,y) point, parent or not). So creating a mouse area to trap the events is a perfectly valid solution.

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      Milnadar
                      wrote on last edited by
                      #10

                      Ok, thanks.
                      And one more question, is there any idea how to deny any item to handle event?

                      1 Reply Last reply
                      0
                      • R Offline
                        R Offline
                        roopeshchander
                        wrote on last edited by
                        #11

                        There's "mouseArea.enabled":http://doc.qt.nokia.com/4.7/qml-mousearea.html#enabled-prop and "flickable.interactive":http://doc.qt.nokia.com/4.7/qml-flickable.html#interactive-prop . Is that what you're looking for?

                        1 Reply Last reply
                        0
                        • M Offline
                          M Offline
                          Milnadar
                          wrote on last edited by
                          #12

                          bq. There’s mouseArea.enabled [doc.qt.nokia.com] and flickable.interactive [doc.qt.nokia.com] . Is that what you’re looking for?

                          Yes, that is it. Thanks to all for help.

                          1 Reply Last reply
                          0

                          • Login

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