I haven't been able to find a tutorial on handling touch events in PyQt or PySide or figure it out from the documentation. Does anyone have a simple program to illustrate how it works?
did you read the "docs":http://qt-project.org/doc/qt-5.0/qtgui/qtouchevent.html#event-handling?!
Yes, that's why I'm confused. In the code below, I can display mouse events but not touch events. What am I doing wrong?
from PySide import QtGui, QtCore
widget = QtGui.QWidget(self)
layout = QtGui.QVBoxLayout(widget)
self.edit = QtGui.QLineEdit(self)
self.list = QtGui.QListWidget(self)
def eventFilter(self, source, event): if event.type() == QtCore.QEvent.MouseMove: if event.buttons() == QtCore.Qt.NoButton: pos = event.pos() self.edit.setText('x: %d, y: %d' % (pos.x(), pos.y())) else: pass # do other stuff elif event.type() == QtCore.QEvent.TouchBegin: pos = event.pos() self.edit.setText('touch x: %d, y: %d' % (pos.x(), pos.y())) return QtGui.QMainWindow.eventFilter(self, source, event)
if name == 'main':
app = QtGui.QApplication(sys.argv)
win = Window()
read the link i've posted again!! this time really ... it's all mentioned very well there...
Instead using pos() of QTouchEvent (which btw. doesn't even exist for this type of event) you should use touchPoints().
Thanks for the response. I'm not receiving events from TouchBegin but I'm receiving events from MouseMove in my event filter even though I used self.setAttribute(QtCore.Qt.WA_AcceptTouchEvents) to accept touch events. There must be something I'm missing but I'm only getting started with Qt and I can't understand the docs as well as you.