[PyQt] touch events is not generating - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: [PyQt] touch events is not generating (/thread-9683.html) |
touch events is not generating - shridhara - Apr-23-2018 hell all, Hi, I tested simple code for detecting touch event on touch-screen, but i cant able to generate touch events and can't pinch at all. Anyone help? Thank you i have done the code,in python and also i have imported .ui file from qt designer and also .png image , please anyone guide me to get this work done... [b]import sys from PyQt4.QtCore import * from PyQt4.QtGui import * from PyQt4.uic import * from types import * app = QApplication(sys.argv) w = loadUi("pinch.ui") img = QImage("pinch.png") painter = QPainter() scale = 1.0 angle = 0.0; def handleEvents(self, event): global scale, angle if event.type() == QEvent.Gesture: g = event.gesture(Qt.PinchGesture) scale = g.totalScaleFactor() angle = g.totalRotationAngle() self.update() elif event.type() == QEvent.Paint: painter.begin(self) painter.rotate(angle) painter.scale(scale, scale) painter.drawImage(0, 0, img) painter.end() return True w.widget.event = MethodType(handleEvents, w.widget) w.widget.grabGesture(Qt.PinchGesture) w.show() sys.exit(app.exec_()) 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] import sys from PyQt4.QtCore import * from PyQt4.QtGui import * from PyQt4.uic import * from types import * app = QApplication(sys.argv) w = loadUi("pinch.ui") img = QImage("pinch.png") painter = QPainter() scale = 1.0 angle = 0.0; def handleEvents(self, event): global scale, angle if event.type() == QEvent.Gesture: g = event.gesture(Qt.PinchGesture) scale = g.totalScaleFactor() angle = g.totalRotationAngle() self.update() elif event.type() == QEvent.Paint: painter.begin(self) painter.rotate(angle) painter.scale(scale, scale) painter.drawImage(0, 0, img) painter.end() return True w.widget.event = MethodType(handleEvents, w.widget) w.widget.grabGesture(Qt.PinchGesture) w.show() sys.exit(app.exec_()) actually iam using spyder2.7 for this coding please if anyone knows please help me how to generare a events or is their any procedure for proper installation .... |