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. QML rectangle TapHandler problem
Forum Updated to NodeBB v4.3 + New Features

QML rectangle TapHandler problem

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
7 Posts 3 Posters 850 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.
  • P Offline
    P Offline
    PhysicsX
    wrote on 27 Oct 2020, 19:40 last edited by
    #1

    Hi everyone,

    I have two rectangles

    Window
    {
          visible: true
          width: 800
          height: 480
     
          Rectangle
          {
          width: 800
          height: 480
          color: "black" 
    
            TapHandler {
                 onTapped: {
                 console.log("rec1");
            }  
           }
         }
          Rectangle
          {
          width: 100
          height: 100
          color: "white" 
    
    
            TapHandler {
                 onTapped: {
                 console.log("rec2");
            }  
           }
         }
    }
    

    When I click black rectangle it prints "rec1" as I expect. When I click white rectangle which is above the black rectangle, it prints "rec2" and "rec1". But I want only "rec2" should be printed.

    What I miss here ? What should I learn or how can I do that ?

    Thank you.

    1 Reply Last reply
    0
    • M Offline
      M Offline
      Markkyboy
      wrote on 27 Oct 2020, 22:59 last edited by Markkyboy
      #2

      When I run your code, I see this;

      black-and-white-rect.JPG

      import QtQuick 2.12
      import QtQuick.Window 2.12
      
      Window {
          visible: true
          width: 800
          height: 480
          color: "red"
      
          Column {
              spacing: 100
      
              Rectangle {
                  width: 100
                  height: 100
                  color: "black"
      
                  TapHandler {
                      onTapped: {
                          console.log("rec1");
                      }
                  }
              }
              Rectangle {
                  width: 100
                  height: 100
                  color: "white"
      
                  TapHandler {
                      onTapped: {
                          console.log("rec2");
                      }
                  }
              }
          }
      }
      

      For Rectangles to be placed above/below each other and be independently clickable, you need to use Column;

      import QtQuick 2.12
      import QtQuick.Window 2.12
      
      Window {
          visible: true
          width: 800
          height: 480
          color: "grey"
      
          Column {
              spacing: 100
      
              Rectangle {
                  width: 100
                  height: 100
                  color: "white"
      
                  TapHandler {
                      onTapped: {
                          console.log("rec1");
                      }
                  }
              }
              Rectangle {
                  width: 100
                  height: 100
                  color: "black"
      
                  TapHandler {
                      onTapped: {
                          console.log("rec2");
                      }
                  }
              }
          }
      }
      

      Just to clarify, I purposely made the black Rectangle the same size as the white one for visibility.

      column-black-white-rect.JPG

      Don't just sit there standing around, pick up a shovel and sweep up!

      I live by the sea, not in it.

      O P 2 Replies Last reply 27 Oct 2020, 23:20
      0
      • M Markkyboy
        27 Oct 2020, 22:59

        When I run your code, I see this;

        black-and-white-rect.JPG

        import QtQuick 2.12
        import QtQuick.Window 2.12
        
        Window {
            visible: true
            width: 800
            height: 480
            color: "red"
        
            Column {
                spacing: 100
        
                Rectangle {
                    width: 100
                    height: 100
                    color: "black"
        
                    TapHandler {
                        onTapped: {
                            console.log("rec1");
                        }
                    }
                }
                Rectangle {
                    width: 100
                    height: 100
                    color: "white"
        
                    TapHandler {
                        onTapped: {
                            console.log("rec2");
                        }
                    }
                }
            }
        }
        

        For Rectangles to be placed above/below each other and be independently clickable, you need to use Column;

        import QtQuick 2.12
        import QtQuick.Window 2.12
        
        Window {
            visible: true
            width: 800
            height: 480
            color: "grey"
        
            Column {
                spacing: 100
        
                Rectangle {
                    width: 100
                    height: 100
                    color: "white"
        
                    TapHandler {
                        onTapped: {
                            console.log("rec1");
                        }
                    }
                }
                Rectangle {
                    width: 100
                    height: 100
                    color: "black"
        
                    TapHandler {
                        onTapped: {
                            console.log("rec2");
                        }
                    }
                }
            }
        }
        

        Just to clarify, I purposely made the black Rectangle the same size as the white one for visibility.

        column-black-white-rect.JPG

        O Offline
        O Offline
        ODБOï
        wrote on 27 Oct 2020, 23:20 last edited by
        #3

        hi
        @Markkyboy said in QML rectangle TapHandler problem:

        For Rectangles to be placed above/below each other and be independently clickable, you need to use Column;

        i think the question is about the z axis
        something like https://doc.qt.io/qt-5/qml-qtquick-mousearea.html#propagateComposedEvents-prop

        M 1 Reply Last reply 28 Oct 2020, 10:32
        0
        • O ODБOï
          27 Oct 2020, 23:20

          hi
          @Markkyboy said in QML rectangle TapHandler problem:

          For Rectangles to be placed above/below each other and be independently clickable, you need to use Column;

          i think the question is about the z axis
          something like https://doc.qt.io/qt-5/qml-qtquick-mousearea.html#propagateComposedEvents-prop

          M Offline
          M Offline
          Markkyboy
          wrote on 28 Oct 2020, 10:32 last edited by
          #4

          @LeLev - thanks, I had a feeling I was not 'on the money' with my answer....doh!, still learning.

          Don't just sit there standing around, pick up a shovel and sweep up!

          I live by the sea, not in it.

          1 Reply Last reply
          0
          • M Markkyboy
            27 Oct 2020, 22:59

            When I run your code, I see this;

            black-and-white-rect.JPG

            import QtQuick 2.12
            import QtQuick.Window 2.12
            
            Window {
                visible: true
                width: 800
                height: 480
                color: "red"
            
                Column {
                    spacing: 100
            
                    Rectangle {
                        width: 100
                        height: 100
                        color: "black"
            
                        TapHandler {
                            onTapped: {
                                console.log("rec1");
                            }
                        }
                    }
                    Rectangle {
                        width: 100
                        height: 100
                        color: "white"
            
                        TapHandler {
                            onTapped: {
                                console.log("rec2");
                            }
                        }
                    }
                }
            }
            

            For Rectangles to be placed above/below each other and be independently clickable, you need to use Column;

            import QtQuick 2.12
            import QtQuick.Window 2.12
            
            Window {
                visible: true
                width: 800
                height: 480
                color: "grey"
            
                Column {
                    spacing: 100
            
                    Rectangle {
                        width: 100
                        height: 100
                        color: "white"
            
                        TapHandler {
                            onTapped: {
                                console.log("rec1");
                            }
                        }
                    }
                    Rectangle {
                        width: 100
                        height: 100
                        color: "black"
            
                        TapHandler {
                            onTapped: {
                                console.log("rec2");
                            }
                        }
                    }
                }
            }
            

            Just to clarify, I purposely made the black Rectangle the same size as the white one for visibility.

            column-black-white-rect.JPG

            P Offline
            P Offline
            PhysicsX
            wrote on 28 Oct 2020, 12:11 last edited by
            #5

            @Markkyboy Thanks for reply, should not move rectangles. white one should stay on top of the black one. When you click the white one, "rec1" should not be printed, only "rec2" should be printed.

            M 1 Reply Last reply 28 Oct 2020, 12:18
            0
            • P PhysicsX
              28 Oct 2020, 12:11

              @Markkyboy Thanks for reply, should not move rectangles. white one should stay on top of the black one. When you click the white one, "rec1" should not be printed, only "rec2" should be printed.

              M Offline
              M Offline
              Markkyboy
              wrote on 28 Oct 2020, 12:18 last edited by
              #6

              @PhysicsX - apologies, I misunderstood your question. I should not be replying late at night! :)

              Don't just sit there standing around, pick up a shovel and sweep up!

              I live by the sea, not in it.

              P 1 Reply Last reply 28 Oct 2020, 16:23
              0
              • M Markkyboy
                28 Oct 2020, 12:18

                @PhysicsX - apologies, I misunderstood your question. I should not be replying late at night! :)

                P Offline
                P Offline
                PhysicsX
                wrote on 28 Oct 2020, 16:23 last edited by
                #7

                @Markkyboy No problem :) This is the exact issue actually https://bugreports.qt.io/browse/QTBUG-85694

                1 Reply Last reply
                1

                1/7

                27 Oct 2020, 19:40

                • Login

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