Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. MousePressEvent Not Functioning Correctly on Touchscreen
Forum Update on Monday, May 27th 2025

MousePressEvent Not Functioning Correctly on Touchscreen

Scheduled Pinned Locked Moved Unsolved Qt for Python
5 Posts 3 Posters 827 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.
  • C Offline
    C Offline
    colinodowd
    wrote on last edited by
    #1

    I am noticing that my MousePressEvent functions are not working as intended when I use the touchscreen functionality of my computer. The buttons on my GUI are intended to change color on a press event and on release, return to original color and perform a function.

    There are four scenarios:
    -Mouse press on the QLabel button and instantly release - Works as intended
    -Mouse press on the QLabel button, drag mouse, and release (slight delay in hold) - Works as intended
    -Finger press on the QLabel and instantly release (normal tap) - does not change image color but performs the -function in MouseReleaseEvent.
    -Finger press on the QLabel, drag finger, and release (slight delay in hold) - Works as intended

    Even a long hold in the same position on scenario 3 doesn't cause the image to change color, I have to drag my finger for a 1/4 second to make it work.
    This is my code:

    self.saveImageBTN = QtWidgets.QLabel(self.cameraViewer)
    self.saveImageBTN.setPixmap(QPixmap("Graphics/saveImageButton.png").scaled(100,100))
    self.saveImageBTN.setGeometry(QtCore.QRect(110, 610, 100, 100))
    self.saveImageBTN.setObjectName("saveImageBTN")
    self.saveImageBTN.mousePressEvent = self.saveImageButtonPress
    self.saveImageBTN.mouseReleaseEvent = self.saveImageButtonRelease
    
    def saveImageButtonPress(self, event):
           self.saveImageBTN.setPixmap(QPixmap("Graphics/saveImageButtonPressed.png").scaled(100,100))
    
    def saveImageButtonRelease(self, event):
           self.saveImageBTN.setPixmap(QPixmap("Graphics/saveImageButton.png").scaled(100,100))
           self.ImagePlayer.saveImage()
    

    I have tried to add delays around the code in my saveImageButtonPress function to account for touchscreen latency but it doesn't seem to help.

    Any help appreciated.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      I would add an event filter to see exactly what is happening during your scenario number 3.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      C 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        I would add an event filter to see exactly what is happening during your scenario number 3.

        C Offline
        C Offline
        colinodowd
        wrote on last edited by
        #3

        @SGaist Hi, I added this code:

        self.saveImageBTN.installEventFilter(self.saveImageBTN)
        
        def eventFilter(self, source, event):
                    if source == self.saveImageBTN:
                        if event.type() == QEvent.Type.MouseButtonPress:
                            print("I am being pressed")
                        if event.type() == QEvent.Type.MouseButtonRelease:
                            print("I am being released")
        
        

        But I do not get any output. I am only seeing the print statements from my mousePressEvent and mouseReleaseEvent functions

        1 Reply Last reply
        0
        • C Offline
          C Offline
          colinodowd
          wrote on last edited by colinodowd
          #4

          I added a standard timer between the events and I am getting 0 microseconds time difference between the saveImageButtonPress and saveImageButtonRelease functions when I use my finger (via touchscreen) to press the button which I don't understand. This is my error because the image never gets to change color before being overwritten. Not sure how to slow this transition down as I have already tried a standard time.sleep() call which did not solve anything.

          When I use the mouse I get anywhere from 0.1-0.3 seconds

          1 Reply Last reply
          0
          • JoeCFDJ Offline
            JoeCFDJ Offline
            JoeCFD
            wrote on last edited by
            #5

            https://forum.qt.io/topic/135219/qt-widgets-not-responding-to-touch-event-sometimes/8
            check this thread out. You may need to check touch event as well.

            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