[PyQt] mouseMoveEvent.button() return always 0

Vincent Vande Vyvre vincent.vande.vyvre at telenet.be
Thu Oct 25 09:35:18 BST 2018


Hi,

I've a subclass QGraphicsScene with a mouseMoveEvent() handler.

I need to know what button is pressed during the move but, strangely, 
the event dont return the button.  It's always 0

Platform Linux-4.15.0-38-generic-x86_64-with-Ubuntu-18.04-bionic
Qt            5.9.5
Python        3.6.6
PyQt        5.10.1
Sip            4.19.7

Example code:
---%<--------------------------------------------------------------------
# -*- coding: utf-8 -*-
import sys
from PyQt5 import QtCore, QtGui, QtWidgets

class Main(QtWidgets.QMainWindow):
     def __init__(self):
         super().__init__()
         self.resize(500, 500)
         self.viewer = QtWidgets.QGraphicsView()
         self.setCentralWidget(self.viewer)
         self.scene = Scene()
         self.viewer.setScene(self.scene)

class Scene(QtWidgets.QGraphicsScene):
     def __init__(self):
         super().__init__()
         self.setSceneRect(0.0, 0.0, 450.0, 450.0)

     def mouseMoveEvent(self, event):
         print(event, "button: ", event.button())

if __name__ == "__main__":
     app = QtWidgets.QApplication([])
     main = Main()
     main.show()
     sys.exit(app.exec_())
---%<--------------------------------------------------------------------


Thanks,

Vincent



More information about the PyQt mailing list