MousePressEvent Not Functioning Correctly on Touchscreen
-
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 intendedEven 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.
-
Hi,
I would add an event filter to see exactly what is happening during your scenario number 3.
-
Hi,
I would add an event filter to see exactly what is happening during your scenario number 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
-
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
-
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.