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. MousePressEvent doesn't get called when left mouse button clicked

MousePressEvent doesn't get called when left mouse button clicked

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 9.3k 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.
  • B Offline
    B Offline
    bergerbits
    wrote on last edited by
    #1

    However it does get called when right or middle mouse button is clicked. Does any one know what's wrong?

    @void MyWindow::mousePressEvent(QMouseEvent *event)
    {
    if(event->button() == Qt::LeftButton)
    std::cout << "left mouse click " << std::endl; // doesn't work
    else if (event->button() == Qt::RightButton)
    std::cout << "right mouse click " << std::endl; // does work
    else if (event->button() == Qt::MidButton)
    std::cout << "middle mouse click " << std::endl; /// does work
    }@

    1 Reply Last reply
    0
    • B Offline
      B Offline
      b1gsnak3
      wrote on last edited by
      #2

      try a qDebug() << event->button(); and check the value... it should be working because the reimplementation seems ok.

      1 Reply Last reply
      0
      • B Offline
        B Offline
        bergerbits
        wrote on last edited by
        #3

        I inserted qDebug statement at head of function. The values 2 and 4 were output upon right and middle mouse button clicks but all was silent for left mouse button click. Can somehow left mouse button event be disabled or accepted already by a parent widget ? Except that MyWindow is a QMainWindow
        ??? hmmmm
        Any suggestions appreciated

        1 Reply Last reply
        0
        • B Offline
          B Offline
          b1gsnak3
          wrote on last edited by
          #4

          Ok this is odd. Sorry but I have no idea as to why this is happening...

          1 Reply Last reply
          0
          • T Offline
            T Offline
            tzander
            wrote on last edited by
            #5

            Reading the docs, you may notice that there is a buttons() (notice the s at the end) as well, which will be more useful for you.
            @
            if ((event->buttons() & Qt::LeftButton) == Qt::LeftButton)
            qDebug() << "Left mouse clicked";
            @

            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