PDA

View Full Version : QMouseEvent called without pressing buttons



EnricoNapoli
2nd January 2014, 11:55
Dear sirs,
I have a problem with the mousePressEvent function.
The program is meant to draw lines using QGLWidget. The program works well when I move the mouse to draw the lines (mouseMoveEvent is called correctly) and when I click the left button (mousePressEvent is called and event->button()=Qt::LeftButton is correctly recognized).
The problem is that, once clicking the mouse Right Button, mousePressEvent is called and event->button()=Qt::RightButton is correctly recognized, but then the function mousePressEvent is called again and again when I move the mouse. It seems that the event is not consumed after the first mousePressEvent calling.
I am using Qt5 with MacOs Mountain Lion and the problem was not there when I was using Qt4 (and Snow Leopard as MacOs system).
The problem occurs in a very long a complicated program, so I am not including the code. But if someone feels it is necessary to take a look in the code I will add it.
Thank you for any help
Enrico

anda_skoa
2nd January 2014, 14:55
Maybe you could try to create a minimal test case, i.e. a program as small as possible that shows the problem.

This makes it easier to test on other systems and can also be used as a suitable test case when eventually filing a bug report against Qt if it is reprodible by others.

Cheers,
_

EnricoNapoli
2nd January 2014, 17:24
Many thanks anda_skoa.

I have reduced the program to the minimum level to show where is the problem and the files are attached.
In the glwidget.cpp file the mousePressEvent, mouseMoveEvent and mouseReleaseEvent have been overloaded as follows:

void GLWidget::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton) QMessageBox::critical(0,0,"left","");
if (event->button() == Qt::RightButton) QMessageBox::critical(0,0,"right","");
}

void GLWidget::mouseMoveEvent(QMouseEvent *event) { }

void GLWidget::mouseReleaseEvent(QMouseEvent *event) { }

Thus nothing should happen when the mouse is moved without clicking the buttons, while a message box with the text "left" or "right" should open when one of the buttons is clicked.
Everything works fine till I click the right button. Then the message box is correctly displayed, but then it continues to be displayed when the mouse is moved without any further button clicking. Why????
It doesn't happen with the left button.
I guess that the problem is not with the code and that it depends on some malfunctioning of my mouse (actually, a trackpad) or on a bug with Qt5.
Do anyone can give me some advice?
Many thanks in advance
Enrico

anda_skoa
2nd January 2014, 23:00
Have you tried with qDebug() output instead of the message boxes?

Message box for debugging seems rather intrusive, moving focus and potentially mouse event target.

Cheers,
_