PyQt5 Events



  • Please can someone help me, I want to trigger the handleEvents() function?

    import sys
    import types
    from types import *
    from PyQt5.QtCore import *
    from PyQt5.QtGui import *
    from PyQt5.QtWidgets import *
     
    import PyQt5.QtCore as core
    import PyQt5.QtGui as gui
    import PyQt5.QtWidgets as widgets
    import PyQt5.uic as uic
     
     
     
     
    import mainwindow_auto
     
    class MainWindow(QMainWindow, mainwindow_auto.Ui_MainWindow):
       def __init__(self):
           super(self.__class__, self).__init__()
           self.setupUi(self)
           self.setGeometry(150, 150, 1280, 600)
           self.setWindowFlags(Qt.FramelessWindowHint)
     
           self.img = gui.QImage("test.png")
           self.painter = gui.QPainter()
           self.transformHistory = gui.QTransform()
           self.transformTotal = gui.QTransform()
           self.startPoint = core.QPoint()
           self.widget = QWidget()
     
           self.widget.grabGesture(core.Qt.PinchGesture)
           self.widget.grabGesture(core.Qt.TapGesture)
           # self.widget.event = types.MethodType(self.handleEvents, self.widget)
     
     
       def handleEvents(self, event):
           print("v")
           global transformHistory, transformTotal, startPoint
           if event.type() == core.QEvent.Gesture:
               print("dddd")
               g = event.gesture(core.Qt.PinchGesture)
               if g != None:
                   upperLeft = self.mapToGlobal(core.QPoint())
                   scale = g.totalScaleFactor()
                   centerPoint = g.centerPoint() - upperLeft
                   if g.state() == core.Qt.GestureStarted:
                       startPoint = g.centerPoint() - upperLeft
                   transformTotal = transformHistory * gui.QTransform().scale(scale, scale)
                   if g.state() == core.Qt.GestureFinished:
                       transformHistory = transformTotal
                   self.update()
               else:
                   g = event.gesture(core.Qt.TapGesture)
                   if g.state() == core.Qt.GestureFinished:
                       print("tap ", g.position())
                       transformTotal = gui.QTransform()
                       transformHistory = gui.QTransform()
                       self.update()
           elif event.type() == core.QEvent.Paint:
               painter = QPainter()
               painter.begin(self)
               painter.setTransform(transformTotal)
               painter.drawImage(0, 0, self.img)
               painter.end()
           return True
     
     
       def keyPressEvent(self, e):
           print("b")
           if e.key() == Qt.Key_Escape:
               self.close()
     
     
     
    if __name__ == '__main__':
       global form
       app = widgets.QApplication(sys.argv)
       form = MainWindow()
       print("a")
       form.show()
       sys.exit(app.exec_())
    
    


Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.