Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. Can not click button when Pinch, Zoom and then drag position
QtWS25 Last Chance

Can not click button when Pinch, Zoom and then drag position

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
12 Posts 3 Posters 1.8k 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.
  • T Offline
    T Offline
    thuongnv284
    wrote on last edited by
    #1

    Hi

    Currently, I have an issue with my app which when Pinch, Zoom and then drag position then i can not click on any button of App

    I searched google but not see someone like me.

    pls help me about this

    Thanks and best regards

    cuongnc

    J.HilkJ 1 Reply Last reply
    0
    • T thuongnv284

      Hi

      Currently, I have an issue with my app which when Pinch, Zoom and then drag position then i can not click on any button of App

      I searched google but not see someone like me.

      pls help me about this

      Thanks and best regards

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @thuongnv284
      hi,

      I don't know how you implemented your Pinch Zoom and Drag functions, but I asume you did it at leas partially by overwriting MouseEvents.

      The solution is simply enough. Only accept Pinch, Zoom and Drag, when a certain minmal distance from the mousepressevent has been exceeded.

      Everything in that margin, you can handle as "clicks"


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      T 1 Reply Last reply
      1
      • J.HilkJ J.Hilk

        @thuongnv284
        hi,

        I don't know how you implemented your Pinch Zoom and Drag functions, but I asume you did it at leas partially by overwriting MouseEvents.

        The solution is simply enough. Only accept Pinch, Zoom and Drag, when a certain minmal distance from the mousepressevent has been exceeded.

        Everything in that margin, you can handle as "clicks"

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

        @J.Hilk thanks for your help

        Could you provide some code for this content or example for more detail.

        thanks you so much

        cuongnc

        J.HilkJ 1 Reply Last reply
        0
        • T thuongnv284

          @J.Hilk thanks for your help

          Could you provide some code for this content or example for more detail.

          thanks you so much

          J.HilkJ Offline
          J.HilkJ Offline
          J.Hilk
          Moderators
          wrote on last edited by
          #4

          @thuongnv284

          signals:
              void clicked();
          private:
          QPoint clickOrigin;
          
          protected:
          void mousePressEvent(QMouseEvent *ev){
              clickOrigin = ev->pos();
              ev->ignore();
          }
          
          void mouseReleaseEvent(QMouseEvent *ev){
              if( (abs(ev->x()- clickOrigin.x())< this->width()/10 )  && (abs(ev->y() -clickOrigin.y()) < this->height()/10) )
              emit clicked();
          
              ev->ignore();
          }
          

          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


          Q: What's that?
          A: It's blue light.
          Q: What does it do?
          A: It turns blue.

          T 1 Reply Last reply
          0
          • J.HilkJ J.Hilk

            @thuongnv284

            signals:
                void clicked();
            private:
            QPoint clickOrigin;
            
            protected:
            void mousePressEvent(QMouseEvent *ev){
                clickOrigin = ev->pos();
                ev->ignore();
            }
            
            void mouseReleaseEvent(QMouseEvent *ev){
                if( (abs(ev->x()- clickOrigin.x())< this->width()/10 )  && (abs(ev->y() -clickOrigin.y()) < this->height()/10) )
                emit clicked();
            
                ev->ignore();
            }
            
            T Offline
            T Offline
            thuongnv284
            wrote on last edited by
            #5

            @J.Hilk Thanks u for help

            I mean i want to process this by QML design

            cuongnc

            J.HilkJ 1 Reply Last reply
            0
            • T thuongnv284

              @J.Hilk Thanks u for help

              I mean i want to process this by QML design

              J.HilkJ Offline
              J.HilkJ Offline
              J.Hilk
              Moderators
              wrote on last edited by
              #6

              @thuongnv284 Well, you haven't mentioned QML at all so far. I'm afraid I can't help you then, I don't have experience with QML.


              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              1 Reply Last reply
              0
              • T Offline
                T Offline
                thuongnv284
                wrote on last edited by
                #7

                Hi

                I found the root of this issue. When i use onClicked property in MouseArea, i see that i can click button on Android instead before i used onPressed.

                cuongnc

                1 Reply Last reply
                0
                • T Offline
                  T Offline
                  thuongnv284
                  wrote on last edited by
                  #8

                  Hi everyone

                  But, i encountered a problem as follow:
                  when i using onClicked i change image of button from image 1 to image 2 and then i want after clicked will change image 2 to image 1. it is same onPressed and onRelease.
                  Do you have any solve for me? thanks you so much

                  cuongnc

                  1 Reply Last reply
                  0
                  • GTDevG Offline
                    GTDevG Offline
                    GTDev
                    wrote on last edited by
                    #9

                    Hi,
                    it is hard to guess what behavior you exactly expect without some more code or information,
                    but why don't you just use a property binding to link the pressed state of the MouseArea to the source for your image?

                    MouseArea {
                      id: mouseArea
                    }
                    
                    Image {
                      source: mouseArea.pressed ? "/path/to/image1" : "/path/to/image2"
                    }
                    

                    Best,
                    GT

                    Senior Developer at Felgo - https://felgo.com/qt

                    Develop mobile Apps for iOS & Android with Qt
                    Felgo is an official Qt Technology Partner

                    T 2 Replies Last reply
                    0
                    • GTDevG GTDev

                      Hi,
                      it is hard to guess what behavior you exactly expect without some more code or information,
                      but why don't you just use a property binding to link the pressed state of the MouseArea to the source for your image?

                      MouseArea {
                        id: mouseArea
                      }
                      
                      Image {
                        source: mouseArea.pressed ? "/path/to/image1" : "/path/to/image2"
                      }
                      

                      Best,
                      GT

                      T Offline
                      T Offline
                      thuongnv284
                      wrote on last edited by
                      #10

                      @GTDev Thanks for your help

                      When you show for me i see that it is really simple. Thanks you so much :)

                      cuongnc

                      1 Reply Last reply
                      0
                      • GTDevG GTDev

                        Hi,
                        it is hard to guess what behavior you exactly expect without some more code or information,
                        but why don't you just use a property binding to link the pressed state of the MouseArea to the source for your image?

                        MouseArea {
                          id: mouseArea
                        }
                        
                        Image {
                          source: mouseArea.pressed ? "/path/to/image1" : "/path/to/image2"
                        }
                        

                        Best,
                        GT

                        T Offline
                        T Offline
                        thuongnv284
                        wrote on last edited by
                        #11

                        @GTDev Hi,

                        Do you know why on Android device if i use onClicked then i can touch but if i use onPressed then i can not? I do not understand the reason of this. Pls help me

                        cuongnc

                        J.HilkJ 1 Reply Last reply
                        0
                        • T thuongnv284

                          @GTDev Hi,

                          Do you know why on Android device if i use onClicked then i can touch but if i use onPressed then i can not? I do not understand the reason of this. Pls help me

                          J.HilkJ Offline
                          J.HilkJ Offline
                          J.Hilk
                          Moderators
                          wrote on last edited by
                          #12

                          @thuongnv284
                          usually the Clicked action is handled after the mouse/finger is released, where as onPressed obvioulsy emits/handles the action when the mouse/finger is first pressed.

                          Gesturehandling lies exactly in between those 2. When the mouse/finger is pressed/on the screen and is moved around.


                          Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                          Q: What's that?
                          A: It's blue light.
                          Q: What does it do?
                          A: It turns blue.

                          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