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.1k Views
  • 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 23 Feb 2013, 07:49 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 23 Feb 2013, 09:38 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 23 Feb 2013, 16:23 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 25 Feb 2013, 08:06 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 25 Feb 2013, 09:06 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

            4/5

            25 Feb 2013, 08:06

            • Login

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