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. Mouse area handling.

Mouse area handling.

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

    I have 3 images and i want one mouse area to handle click events for all the 3 images. Is it possible?
    Note: I don't want 3 different mouse area. Only one mouse area.

    1 Reply Last reply
    0
    • Shrinidhi UpadhyayaS Offline
      Shrinidhi UpadhyayaS Offline
      Shrinidhi Upadhyaya
      wrote on last edited by
      #2

      Hi @JasmineSethi , you can do one thing you can enclose all the 3 images under one Item and give that item a Mousearea.

      For example:-

        Item {
               id: root
           [..]
           [..]
           Image {
               id: image1
               [..]
               [..]
           }
           Image {
               id: image2
               [..]
               [..]
           }
           Image {
               id: image3
               [..]
               [..]
           }
      
       MouseArea {
           anchors.fill: parent
      
           onClicked: {
           [..]
           console.log("Clicked")
           [..]
        }
      }
      

      Shrinidhi Upadhyaya.
      Upvote the answer(s) that helped you to solve the issue.

      J 1 Reply Last reply
      0
      • Shrinidhi UpadhyayaS Shrinidhi Upadhyaya

        Hi @JasmineSethi , you can do one thing you can enclose all the 3 images under one Item and give that item a Mousearea.

        For example:-

          Item {
                 id: root
             [..]
             [..]
             Image {
                 id: image1
                 [..]
                 [..]
             }
             Image {
                 id: image2
                 [..]
                 [..]
             }
             Image {
                 id: image3
                 [..]
                 [..]
             }
        
         MouseArea {
             anchors.fill: parent
        
             onClicked: {
             [..]
             console.log("Clicked")
             [..]
          }
        }
        
        J Offline
        J Offline
        JasmineSethi
        wrote on last edited by
        #3

        @Shrinidhi-Upadhyaya Hi, this will not solve my problem because onclick is accessible outside the image also. I want onclick to accessible only inside the images.

        Shrinidhi UpadhyayaS 1 Reply Last reply
        0
        • J JasmineSethi

          @Shrinidhi-Upadhyaya Hi, this will not solve my problem because onclick is accessible outside the image also. I want onclick to accessible only inside the images.

          Shrinidhi UpadhyayaS Offline
          Shrinidhi UpadhyayaS Offline
          Shrinidhi Upadhyaya
          wrote on last edited by
          #4

          @JasmineSethi , you can give the Item(id: root) the combined height and width of the rectangle, so that the click does not happen outside the 3 images. Can you please tell me a bit more about what exactly do you want, like how you are going to position the 3Images and what you want to do on the click,so that i can give you a more optimal solution.

          Shrinidhi Upadhyaya.
          Upvote the answer(s) that helped you to solve the issue.

          J 1 Reply Last reply
          0
          • Shrinidhi UpadhyayaS Shrinidhi Upadhyaya

            @JasmineSethi , you can give the Item(id: root) the combined height and width of the rectangle, so that the click does not happen outside the 3 images. Can you please tell me a bit more about what exactly do you want, like how you are going to position the 3Images and what you want to do on the click,so that i can give you a more optimal solution.

            J Offline
            J Offline
            JasmineSethi
            wrote on last edited by
            #5

            @Shrinidhi-Upadhyaya

            import QtQuick 2.0

            Rectangle
            {
            width: 400
            height: 300
            Item
            {
            width: parent.width
            height: 300
            Image
            {
            id: first
            source: "Selected.png"
            Text
            {
            text: qsTr("Image 1")
            color: "black"
            font.pixelSize: 10
            anchors.centerIn: parent
            }
            }
            Image
            {
            id: second
            anchors.left: first.right
            source: "Selected.png"
            Text
            {
            text: qsTr("Image 2")
            color: "black"
            font.pixelSize: 10
            anchors.centerIn: parent
            }
            }
            Image
            {
            id: third
            anchors.left: second.right
            source: "Selected.png"
            Text
            {
            text: qsTr("Image 3")
            color: "black"
            font.pixelSize: 10
            anchors.centerIn: parent
            }
            }
            MouseArea
            {
            anchors.fill: parent
            onClicked: {
            console.log("clicked")
            }
            }

            }
            

            }

            0_1552454994321_323ceed6-c276-4e74-86d2-6a06ba634162-image.png

            I want like this.

            1 Reply Last reply
            0
            • Shrinidhi UpadhyayaS Offline
              Shrinidhi UpadhyayaS Offline
              Shrinidhi Upadhyaya
              wrote on last edited by
              #6

              Hi @JasmineSethi , here is the code:-

               Item {
                  width: 400
                  height: 300
              
                  RowLayout {
                      anchors.fill: parent
                      spacing: 0
              
                      Repeater {
                          model: 3
              
                          Image{
                              Layout.fillHeight: true
                              Layout.fillWidth: true
              
                              Text {
                                  text: "Image" + index
                                  anchors.centerIn: parent
                              }
              
                              MouseArea {
                                  anchors.fill: parent
                                  onClicked: {
                                      console.log("Clicked")
                                  }
                              }
                          }
                      }
                  }
              }
              

              Shrinidhi Upadhyaya.
              Upvote the answer(s) that helped you to solve the issue.

              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