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 851 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 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
    • MarkkyboyM Offline
      MarkkyboyM Offline
      Markkyboy
      wrote on 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.

      ODБOïO P 2 Replies Last reply
      0
      • MarkkyboyM Markkyboy

        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

        ODБOïO Offline
        ODБOïO Offline
        ODБOï
        wrote on 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

        MarkkyboyM 1 Reply Last reply
        0
        • ODБOïO ODБOï

          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

          MarkkyboyM Offline
          MarkkyboyM Offline
          Markkyboy
          wrote on 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
          • MarkkyboyM Markkyboy

            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 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.

            MarkkyboyM 1 Reply Last reply
            0
            • P PhysicsX

              @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.

              MarkkyboyM Offline
              MarkkyboyM Offline
              Markkyboy
              wrote on 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
              0
              • MarkkyboyM Markkyboy

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

                P Offline
                P Offline
                PhysicsX
                wrote on 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

                • Login

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