[prev in list] [next in list] [prev in thread] [next in thread] 

List:       pykde
Subject:    Re: [PyQt] mouseMoveEvent.button() return always 0
From:       Vincent Vande Vyvre <vincent.vande.vyvre () telenet ! be>
Date:       2018-10-26 11:21:31
Message-ID: 0ba8b6e7-2080-69ef-ae1a-3691688f6c40 () telenet ! be
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


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@telenet.be 
> <mailto:vincent.vande.vyvre@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@riverbankcomputing.com
>     <mailto:PyQt@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


[Attachment #5 (text/html)]

<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <div class="moz-cite-prefix">Le 25/10/18 à 19:18, Maurizio Berti a
      écrit :<br>
    </div>
    <blockquote type="cite"
cite="mid:CAPn+-XRe3Ypxeo+w6+xV9+ni3S9WUf+QkBJOcE70Xhz6-6jmyQ@mail.gmail.com">
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <div dir="ltr">
        <div dir="ltr">
          <div dir="ltr">The behavior is similar to QWidget's
            mouseMoveEvent ( <a
              href="http://doc.qt.io/archives/qt-4.8/qmouseevent.html#button"
              moz-do-not-send="true">http://doc.qt.io/archives/qt-4.8/qmouseevent.html#button</a>
  ):<br>
            <br>
            <blockquote class="gmail_quote" style="margin:0px 0px 0px
              0.8ex;border-left:1px solid
              rgb(204,204,204);padding-left:1ex">Note that the returned
              value is always Qt::NoButton for mouse move events</blockquote>
            <br>
          </div>
          <div>Also, as soon as a mousePressEvent is catched, Qt always
            sends a mouseMoveEvent, and for that first event only, the
            button() result is correct.</div>
          <div>You have to use buttons() instead :-)</div>
          <div><br>
          </div>
        </div>
      </div>
      <br>
      <div class="gmail_quote">
        <div dir="ltr">Il giorno gio 25 ott 2018 alle ore 10:36 Vincent
          Vande Vyvre &lt;<a
            href="mailto:vincent.vande.vyvre@telenet.be"
            moz-do-not-send="true">vincent.vande.vyvre@telenet.be</a>&gt;
          ha scritto:<br>
        </div>
        <blockquote class="gmail_quote" style="margin:0 0 0
          .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
          <br>
          I've a subclass QGraphicsScene with a mouseMoveEvent()
          handler.<br>
          <br>
          I need to know what button is pressed during the move but,
          strangely, <br>
          the event dont return the button.  It's always 0<br>
          <br>
          Platform
          Linux-4.15.0-38-generic-x86_64-with-Ubuntu-18.04-bionic<br>
          Qt            5.9.5<br>
          Python        3.6.6<br>
          PyQt        5.10.1<br>
          Sip            4.19.7<br>
          <br>
          Example code:<br>
---%&lt;--------------------------------------------------------------------<br>
          # -*- coding: utf-8 -*-<br>
          import sys<br>
          from PyQt5 import QtCore, QtGui, QtWidgets<br>
          <br>
          class Main(QtWidgets.QMainWindow):<br>
               def __init__(self):<br>
                   super().__init__()<br>
                   self.resize(500, 500)<br>
                   self.viewer = QtWidgets.QGraphicsView()<br>
                   self.setCentralWidget(self.viewer)<br>
                   self.scene = Scene()<br>
                   self.viewer.setScene(self.scene)<br>
          <br>
          class Scene(QtWidgets.QGraphicsScene):<br>
               def __init__(self):<br>
                   super().__init__()<br>
                   self.setSceneRect(0.0, 0.0, 450.0, 450.0)<br>
          <br>
               def mouseMoveEvent(self, event):<br>
                   print(event, "button: ", event.button())<br>
          <br>
          if __name__ == "__main__":<br>
               app = QtWidgets.QApplication([])<br>
               main = Main()<br>
               main.show()<br>
               sys.exit(app.exec_())<br>
---%&lt;--------------------------------------------------------------------<br>
          <br>
          <br>
          Thanks,<br>
          <br>
          Vincent<br>
          <br>
          _______________________________________________<br>
          PyQt mailing list    <a
            href="mailto:PyQt@riverbankcomputing.com" target="_blank"
            moz-do-not-send="true">PyQt@riverbankcomputing.com</a><br>
          <a
            href="https://www.riverbankcomputing.com/mailman/listinfo/pyqt"
            rel="noreferrer" target="_blank" \
moz-do-not-send="true">https://www.riverbankcomputing.com/mailman/listinfo/pyqt</a></blockquote>
  </div>
      <br clear="all">
      <div><br>
      </div>
      -- <br>
      <div dir="ltr" class="gmail_signature"
        data-smartmail="gmail_signature">È difficile avere una
        convinzione precisa quando si parla delle ragioni del cuore. -
        "Sostiene Pereira", Antonio Tabucchi<br>
        <a href="http://www.jidesk.net" target="_blank"
          moz-do-not-send="true">http://www.jidesk.net</a></div>
    </blockquote>
    <p>Thanks Maurizio for the explanation, that's works with buttons()</p>
    <p>Vincent<br>
    </p>
  </body>
</html>


[Attachment #6 (text/plain)]

_______________________________________________
PyQt mailing list    PyQt@riverbankcomputing.com
https://www.riverbankcomputing.com/mailman/listinfo/pyqt

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic