MousePressEvent doesn't get called when left mouse button clicked
-
wrote on 23 Feb 2013, 07:49 last edited by
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
}@ -
wrote on 23 Feb 2013, 09:38 last edited by
try a qDebug() << event->button(); and check the value... it should be working because the reimplementation seems ok.
-
wrote on 23 Feb 2013, 16:23 last edited by
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 -
wrote on 25 Feb 2013, 08:06 last edited by
Ok this is odd. Sorry but I have no idea as to why this is happening...
-
wrote on 25 Feb 2013, 09:06 last edited by
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";
@
3/5