[PyQt] mouseMoveEvent.button() return always 0

Vincent Vande Vyvre vincent.vande.vyvre at telenet.be
Fri Oct 26 12:21:31 BST 2018


Le 25/10/18 à 19:18, Maurizio Berti a écrit :
> The behavior is similar to QWidget's mouseMoveEvent ( 
> http://doc.qt.io/archives/qt-4.8/qmouseevent.html#button ):
>
>     Note that the returned value is always Qt::NoButton for mouse move
>     events
>
>
> Also, as soon as a mousePressEvent is catched, Qt always sends a 
> mouseMoveEvent, and for that first event only, the button() result is 
> correct.
> You have to use buttons() instead :-)
>
>
> Il giorno gio 25 ott 2018 alle ore 10:36 Vincent Vande Vyvre 
> <vincent.vande.vyvre at telenet.be 
> <mailto:vincent.vande.vyvre at telenet.be>> ha scritto:
>
>     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
>
>     _______________________________________________
>     PyQt mailing list PyQt at riverbankcomputing.com
>     <mailto:PyQt at riverbankcomputing.com>
>     https://www.riverbankcomputing.com/mailman/listinfo/pyqt
>
>
>
> -- 
> È difficile avere una convinzione precisa quando si parla delle 
> ragioni del cuore. - "Sostiene Pereira", Antonio Tabucchi
> http://www.jidesk.net

Thanks Maurizio for the explanation, that's works with buttons()

Vincent

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20181026/9a25aa6e/attachment.html>


More information about the PyQt mailing list