Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. mouseMoveEvent() does not give information about the button that was pressed

mouseMoveEvent() does not give information about the button that was pressed

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 297 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • mrjbomM Offline
    mrjbomM Offline
    mrjbom
    wrote on last edited by mrjbom
    #1

    Hi.

    I have overloaded several functions to handle mouse events

    void mousePressEvent(QMouseEvent *event) override;
    void mouseReleaseEvent(QMouseEvent *event) override;
    void mouseMoveEvent(QMouseEvent *event) override;
    

    In the first two functions, when using event->button() I get the correct button.

    However, in the case of mouseMoveEvent(), I get Qt::NoButton.
    For me, this event only occurs when I move the mouse with the mouse button held down.
    Why is this happening?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      No it does not, you might have enabled mouse tracking on your widget and therefore your will get this event without or without button pressed.

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      mrjbomM 1 Reply Last reply
      0
      • SGaistS SGaist

        Hi,

        No it does not, you might have enabled mouse tracking on your widget and therefore your will get this event without or without button pressed.

        mrjbomM Offline
        mrjbomM Offline
        mrjbom
        wrote on last edited by mrjbom
        #3

        @SGaist No.
        I realized that this is normal, the documentation for the button() method says: "Note that the returned value is always Qt::NoButton for mouse move events."
        Thanks for answer.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Indeed it is in the documentation. I thought you were questioning that so I was answering to this particular sentence:
          @mrjbom said in mouseMoveEvent() does not give information about the button that was pressed:

          For me, this event only occurs when I move the mouse with the mouse button held down.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved