Python Forum

Full Version: PyQt4 Touch events
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I tested simple code for detecting touch event on touch-screen, but QEvent.TouchBegin, QEvent.TouchUpdate, QEvent.TouchEnd are not detected at all. Anyone help? Thank you.

import sys
import math

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.uic import *
from types import *

def handleEvent(self, event):
   if event.type() in [QEvent.TouchBegin, QEvent.TouchUpdate, QEvent.TouchEnd]:
       print ("Touch event")
       print (event.type())
       tp = event.toichPoints()
       for p in tp:
           print(p.pos())

   return True



app = QApplication(sys.argv)
w = loadUi("main.ui")

w.widget.setAttribute(Qt.WA_AcceptTouchEvents)

w.widget.event = MethodType(handleEvent, w.widget)

w.show()
sys.exit(app.exec_())
[color=#000000][font=DejaVu Sans Mono]
Have to assured that the handelEvent function is ever being called?
(add print statement as first item).
First thing you need to know is are events actually being triggered.
Yes, I added print statement right before if statement in the handleEvent function, I was printing the event type, and I was getting results.
Also, I tested the mouse move event, that works, but the touch event is not registered. I dont know what am I missing?