Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 [PyQt] touch events is not generating
#1
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 ....
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Tkinter touch screen button click ashtona 2 2,670 Apr-13-2018, 11:46 AM
Last Post: buran
  PyQt4 Touch events alekssandrap 2 2,884 Jan-28-2017, 01:05 PM
Last Post: alekssandrap

Forum Jump:


Users browsing this thread: 1 Guest(s)