mouseMoveEvent and mouseReleaseEvent have no effect in QGrapicsView in pyqt

Viewed 20

I try to use mouseMoveEvent and mouseReleaseEvent , but they don't work , I hope there is simpler way than using eventFilter

from PyQt5.QtWidgets import QApplication, QWidget,QHBoxLayout,QGraphicsScene, QGraphicsView

class Window(QWidget):
    
    def __init__(self):
        super().__init__()
        
        self.setGeometry(400, 50, 800, 700)
        scene = QGraphicsScene(-180, -90, 360, 180)
        view = QGraphicsView(scene)
        
        layout = QHBoxLayout(self)
        layout.addWidget(view)
        view.scale(1,-1)
        self.setLayout(layout)
        
    def mousePressEvent(self, event):
        print('pressed')

    def mouseMoveEvent(self, event):
        print('moving')
        
    def mouseReleaseEvent(self, event):
        print('released')
        
if __name__ == '__main__':
    app = QApplication([])
    window = Window()
    window.show()
    app.exec()
0 Answers
Related