Thanks, you had right. Needed to do something like that, but I didn't know how to do it. I tried QGestures which was my first choise, but I didn't find any information for pyqt and I didn't manage to make it work either. Finally I found moosegestrures library which does more that I want, but again no much info about that. It has some pygame examples though, and with those I managed to do what I wanted(probably not with an elegant way).
So here is how I did it:
class MainWindow(QMainWindow, Ui_MainWindow):
def __init__(self, parent=None):
super(MainWindow,self).__init__(parent)
self.old_x = QCursor.pos().x()
self.old_y = QCursor.pos().y()
self.setupUi(self)
self.frame.setMouseTracking(True)
self.frame.installEventFilter(self)
self.points[]
....
def eventFilter(self, source, event):
if event.type() == QtCore.QEvent.MouseMove:
#if event.buttons() == QtCore.Qt.NoButton:
# print("Simple mouse motion")
if event.buttons() == QtCore.Qt.LeftButton:
if len(self.points) > 2:
startx, starty = self.points[0][0], self.points[0][1]
for i in range(len(self.points)):
self.points[i] = (self.points[i][0] - startx, self.points[i][1] - starty)
self.points.append((event.localPos().x(), event.localPos().y()))
print(self.points)
#self.points = []
elif event.type() == QtCore.QEvent.MouseButtonRelease:
if event.button() == QtCore.Qt.LeftButton:
print("Released!")
self.mouseDown = False
strokes = moosegesture.getGesture(self.points)
strokeText=str(strokes[-1])
#print(strokeText)
if strokeText == "R":
self.matrix, done = logic.right(self.matrix)
if done:
self.stateCheck()
if strokeText == "L":
self.matrix, done = logic.left(self.matrix)
if done:
self.stateCheck()
if strokeText == "U":
self.matrix, done = logic.up(self.matrix)
if done:
self.stateCheck()
if strokeText == "D":
self.matrix, done = logic.down(self.matrix)
if done:
self.stateCheck()
return self.frame.eventFilter(source, event)