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. Independence MouseArea.
Qt 6.11 is out! See what's new in the release blog

Independence MouseArea.

Scheduled Pinned Locked Moved Solved QML and Qt Quick
qmlc++
12 Posts 3 Posters 4.7k 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.
  • dheerendraD Offline
    dheerendraD Offline
    dheerendra
    Moderators Qt Champions 2024 Qt Champions 2022 Qt Champions 2017
    wrote on last edited by
    #2

    Question is confusing. What is the behaviour you are looking for ? Can you add more details ? What you want to fix ? I ran your program. It shows the two rounded rectangle & there is one round button inside the rounded rectangle. Beyond this what that you are expecting ? Please add more details.

    Dheerendra
    @Community Service
    Certified Qt Specialist
    https://www.pthinks.com

    T 1 Reply Last reply
    3
    • dheerendraD dheerendra

      Question is confusing. What is the behaviour you are looking for ? Can you add more details ? What you want to fix ? I ran your program. It shows the two rounded rectangle & there is one round button inside the rounded rectangle. Beyond this what that you are expecting ? Please add more details.

      T Offline
      T Offline
      TheGringerEye
      wrote on last edited by
      #3

      @dheerendra is custom joysticks. I want to control joysticks with two fingers at the same time.

      1 Reply Last reply
      0
      • dheerendraD Offline
        dheerendraD Offline
        dheerendra
        Moderators Qt Champions 2024 Qt Champions 2022 Qt Champions 2017
        wrote on last edited by
        #4

        With mouseArea it is not possible. Mouse is singleTouch device. You need to use the MultiTouchArea for this to work.

        Dheerendra
        @Community Service
        Certified Qt Specialist
        https://www.pthinks.com

        T 2 Replies Last reply
        2
        • dheerendraD dheerendra

          With mouseArea it is not possible. Mouse is singleTouch device. You need to use the MultiTouchArea for this to work.

          T Offline
          T Offline
          TheGringerEye
          wrote on last edited by
          #5

          @dheerendra said in Independence MouseArea.:

          MultiTouchArea

          I know, i deploy my application on android device.

          1 Reply Last reply
          0
          • dheerendraD dheerendra

            With mouseArea it is not possible. Mouse is singleTouch device. You need to use the MultiTouchArea for this to work.

            T Offline
            T Offline
            TheGringerEye
            wrote on last edited by
            #6

            @dheerendra MultiPointTouchArea don't have drag&drop.

            1 Reply Last reply
            0
            • dheerendraD Offline
              dheerendraD Offline
              dheerendra
              Moderators Qt Champions 2024 Qt Champions 2022 Qt Champions 2017
              wrote on last edited by
              #7

              do u want to do drag & drop one area to another at some time using two fingers ? Not clear about the drag-drop with multi touch request.

              Dheerendra
              @Community Service
              Certified Qt Specialist
              https://www.pthinks.com

              T 2 Replies Last reply
              0
              • dheerendraD dheerendra

                do u want to do drag & drop one area to another at some time using two fingers ? Not clear about the drag-drop with multi touch request.

                T Offline
                T Offline
                TheGringerEye
                wrote on last edited by
                #8

                @dheerendra I try to show - https://www.youtube.com/watch?v=5uaJbqMCaf8&feature=youtu.be

                1 Reply Last reply
                0
                • dheerendraD dheerendra

                  do u want to do drag & drop one area to another at some time using two fingers ? Not clear about the drag-drop with multi touch request.

                  T Offline
                  T Offline
                  TheGringerEye
                  wrote on last edited by
                  #9

                  @dheerendra I can not synchronously control two joysticks. Do you understand me?

                  johngodJ 1 Reply Last reply
                  0
                  • T TheGringerEye

                    @dheerendra I can not synchronously control two joysticks. Do you understand me?

                    johngodJ Offline
                    johngodJ Offline
                    johngod
                    wrote on last edited by
                    #10

                    @TheGringerEye You cannot use 2 mouse areas it wont work. The way to got is to use MultiPointTouchArea and TouchPoint. MultiPointTouchArea doesnt have the drag option so you will have to mimic yourself. Here's a hacky implementation that you can adapt to your use case:

                    property bool point1IsJoystick1: false
                        property bool point1IsJoystick2: false
                    
                        property bool point2IsJoystick1: false
                        property bool point2IsJoystick2: false
                    
                    
                        MultiPointTouchArea {
                          anchors.fill: parent
                          touchPoints: [
                              TouchPoint {
                                  id: point1
                    
                                  onPressedChanged: {
                                      if (pressed) {
                                          //console.log("startX: "+startX)
                                          if (joyStick1Pressed(startX, startY)) {
                                              point1IsJoystick1 = true
                                          }
                    
                                          if (joyStick2Pressed(startX, startY)) {
                                              point1IsJoystick2 = true
                                          }
                                      }
                                      else {
                                          point1IsJoystick2 = false
                                          point1IsJoystick1 = false
                                      }
                    
                                  }
                    
                                  onXChanged: {
                                      console.log("startX: "+startX)
                                      if (point1IsJoystick1) {
                                          joyStick1BtnMove(x, y)
                                      }
                    
                                      if (point1IsJoystick2) {
                                          joyStick2BtnMove(x, y)
                                      }
                                  }
                    
                                  onYChanged: {
                                      console.log("startX: "+startX)
                                      if (point1IsJoystick1) {
                                          joyStick1BtnMove(x, y)
                                      }
                    
                                      if (point1IsJoystick2) {
                                          joyStick2BtnMove(x, y)
                                      }
                                  }
                    
                    
                    
                              },
                              TouchPoint {
                                  id: point2
                    
                                  onPressedChanged: {
                                      if (pressed) {
                                          //console.log("startX: "+startX)
                                          if (joyStick1Pressed(startX, startY)) {
                                              point2IsJoystick1 = true
                                          }
                    
                                          if (joyStick2Pressed(startX, startY)) {
                                              point2IsJoystick2 = true
                                          }
                                      }
                                      else {
                                          point2IsJoystick2 = false
                                          point2IsJoystick1 = false
                                      }
                    
                                  }
                    
                                  onXChanged: {
                                      console.log("startX: "+startX)
                                      if (point2IsJoystick1) {
                                          joyStick1BtnMove(x, y)
                                      }
                    
                                      if (point2IsJoystick2) {
                                          joyStick2BtnMove(x, y)
                                      }
                                  }
                    
                                  onYChanged: {
                                      console.log("startX: "+startX)
                                      if (point2IsJoystick1) {
                                          joyStick1BtnMove(x, y)
                                      }
                    
                                      if (point2IsJoystick2) {
                                          joyStick2BtnMove(x, y)
                                      }
                                  }
                    
                              }
                    
                          ]
                    
                    
                          Rectangle {
                            id: joystick1
                            width: 50
                            height: 150
                            color: "gray"
                            radius: 25
                            x: 150
                            y: 20
                          }
                    
                          Rectangle {
                            id: joystick1Btn
                            width: 50
                            height: 50
                            radius: 25
                            color: "blue"
                            x: joystick1.x
                            y: joystick1.y
                          }
                    
                    
                          Rectangle {
                            id: joystick2
                            width: 150
                            height: 50
                            x: 300
                            y: 200
                            color: "gray"
                            radius: 25
                          }
                    
                          Rectangle {
                            id: joystick2Btn
                            width: 50
                            height: 50
                            radius: 25
                            color: "blue"
                            x: joystick2.x
                            y: joystick2.y
                          }
                    
                        }//MultiPointTouchArea
                    
                    
                    
                        function joyStick1Pressed(xx, yy) {
                            if (    xx >= joystick1Btn.x && xx <= joystick1Btn.x+joystick1Btn.width
                                    && yy >= joystick1Btn.y && yy <= joystick1Btn.y+joystick1Btn.height) {
                                console.log("click inside joystick1")
                                return true;
                            }
                            else {
                                console.log("click outside joystick1")
                                return false;
                            }
                        }
                    
                        function joyStick1BtnMove(xx, yy) {
                            if (yy > joystick1.y+joystick1.height-joystick1Btn.height)
                                joystick1Btn.y = joystick1.y+joystick1.height-joystick1Btn.height
                             else if(yy < joystick1.y)
                                joystick1Btn.y = joystick1.y
                            else
                                joystick1Btn.y = yy
                        }
                    
                    
                    
                        function joyStick2Pressed(xx, yy) {
                              if (    xx >= joystick2Btn.x && xx <= joystick2Btn.x+joystick2Btn.width
                                    && yy >= joystick2Btn.y && yy <= joystick2Btn.y+joystick2Btn.height) {
                                //console.log("click inside joystick2")
                                return true;
                            }
                            else {
                                //console.log("click outside joystick2")
                                return false;
                            }
                        }
                    
                        function joyStick2BtnMove(xx, yy) {
                            if (xx < joystick2.x)
                                joystick2Btn.x = joystick2.x
                             else if(xx > joystick2.x+joystick2.width-joystick2Btn.width)
                                joystick2Btn.x = joystick2.x+joystick2.width-joystick2Btn.width
                            else
                                joystick2Btn.x = xx
                        }
                    
                    
                    
                    
                    T 1 Reply Last reply
                    0
                    • T Offline
                      T Offline
                      TheGringerEye
                      wrote on last edited by
                      #11
                      This post is deleted!
                      1 Reply Last reply
                      0
                      • johngodJ johngod

                        @TheGringerEye You cannot use 2 mouse areas it wont work. The way to got is to use MultiPointTouchArea and TouchPoint. MultiPointTouchArea doesnt have the drag option so you will have to mimic yourself. Here's a hacky implementation that you can adapt to your use case:

                        property bool point1IsJoystick1: false
                            property bool point1IsJoystick2: false
                        
                            property bool point2IsJoystick1: false
                            property bool point2IsJoystick2: false
                        
                        
                            MultiPointTouchArea {
                              anchors.fill: parent
                              touchPoints: [
                                  TouchPoint {
                                      id: point1
                        
                                      onPressedChanged: {
                                          if (pressed) {
                                              //console.log("startX: "+startX)
                                              if (joyStick1Pressed(startX, startY)) {
                                                  point1IsJoystick1 = true
                                              }
                        
                                              if (joyStick2Pressed(startX, startY)) {
                                                  point1IsJoystick2 = true
                                              }
                                          }
                                          else {
                                              point1IsJoystick2 = false
                                              point1IsJoystick1 = false
                                          }
                        
                                      }
                        
                                      onXChanged: {
                                          console.log("startX: "+startX)
                                          if (point1IsJoystick1) {
                                              joyStick1BtnMove(x, y)
                                          }
                        
                                          if (point1IsJoystick2) {
                                              joyStick2BtnMove(x, y)
                                          }
                                      }
                        
                                      onYChanged: {
                                          console.log("startX: "+startX)
                                          if (point1IsJoystick1) {
                                              joyStick1BtnMove(x, y)
                                          }
                        
                                          if (point1IsJoystick2) {
                                              joyStick2BtnMove(x, y)
                                          }
                                      }
                        
                        
                        
                                  },
                                  TouchPoint {
                                      id: point2
                        
                                      onPressedChanged: {
                                          if (pressed) {
                                              //console.log("startX: "+startX)
                                              if (joyStick1Pressed(startX, startY)) {
                                                  point2IsJoystick1 = true
                                              }
                        
                                              if (joyStick2Pressed(startX, startY)) {
                                                  point2IsJoystick2 = true
                                              }
                                          }
                                          else {
                                              point2IsJoystick2 = false
                                              point2IsJoystick1 = false
                                          }
                        
                                      }
                        
                                      onXChanged: {
                                          console.log("startX: "+startX)
                                          if (point2IsJoystick1) {
                                              joyStick1BtnMove(x, y)
                                          }
                        
                                          if (point2IsJoystick2) {
                                              joyStick2BtnMove(x, y)
                                          }
                                      }
                        
                                      onYChanged: {
                                          console.log("startX: "+startX)
                                          if (point2IsJoystick1) {
                                              joyStick1BtnMove(x, y)
                                          }
                        
                                          if (point2IsJoystick2) {
                                              joyStick2BtnMove(x, y)
                                          }
                                      }
                        
                                  }
                        
                              ]
                        
                        
                              Rectangle {
                                id: joystick1
                                width: 50
                                height: 150
                                color: "gray"
                                radius: 25
                                x: 150
                                y: 20
                              }
                        
                              Rectangle {
                                id: joystick1Btn
                                width: 50
                                height: 50
                                radius: 25
                                color: "blue"
                                x: joystick1.x
                                y: joystick1.y
                              }
                        
                        
                              Rectangle {
                                id: joystick2
                                width: 150
                                height: 50
                                x: 300
                                y: 200
                                color: "gray"
                                radius: 25
                              }
                        
                              Rectangle {
                                id: joystick2Btn
                                width: 50
                                height: 50
                                radius: 25
                                color: "blue"
                                x: joystick2.x
                                y: joystick2.y
                              }
                        
                            }//MultiPointTouchArea
                        
                        
                        
                            function joyStick1Pressed(xx, yy) {
                                if (    xx >= joystick1Btn.x && xx <= joystick1Btn.x+joystick1Btn.width
                                        && yy >= joystick1Btn.y && yy <= joystick1Btn.y+joystick1Btn.height) {
                                    console.log("click inside joystick1")
                                    return true;
                                }
                                else {
                                    console.log("click outside joystick1")
                                    return false;
                                }
                            }
                        
                            function joyStick1BtnMove(xx, yy) {
                                if (yy > joystick1.y+joystick1.height-joystick1Btn.height)
                                    joystick1Btn.y = joystick1.y+joystick1.height-joystick1Btn.height
                                 else if(yy < joystick1.y)
                                    joystick1Btn.y = joystick1.y
                                else
                                    joystick1Btn.y = yy
                            }
                        
                        
                        
                            function joyStick2Pressed(xx, yy) {
                                  if (    xx >= joystick2Btn.x && xx <= joystick2Btn.x+joystick2Btn.width
                                        && yy >= joystick2Btn.y && yy <= joystick2Btn.y+joystick2Btn.height) {
                                    //console.log("click inside joystick2")
                                    return true;
                                }
                                else {
                                    //console.log("click outside joystick2")
                                    return false;
                                }
                            }
                        
                            function joyStick2BtnMove(xx, yy) {
                                if (xx < joystick2.x)
                                    joystick2Btn.x = joystick2.x
                                 else if(xx > joystick2.x+joystick2.width-joystick2Btn.width)
                                    joystick2Btn.x = joystick2.x+joystick2.width-joystick2Btn.width
                                else
                                    joystick2Btn.x = xx
                            }
                        
                        
                        
                        
                        T Offline
                        T Offline
                        TheGringerEye
                        wrote on last edited by
                        #12

                        @johngod Okay, Thanks, i try it.

                        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