I recently upgraded to Qt 5.10.1 from 5.2 and found that my QPushButtons required more than a single click for the release signal to be emitted. For a pared down example, consider:
MyButton
::MyButton(QWidget *parent
) : {
}
{
qDebug() << "MOUSE PRESS!";
}
{
qDebug() << "MOUSE RELEASE!";
}
{
qDebug() << "MOUSE MOVE!";
}
MyButton::MyButton(QWidget *parent) :
QPushButton(parent)
{
}
void MyButton::mousePressEvent(QMouseEvent *event)
{
qDebug() << "MOUSE PRESS!";
QPushButton::mousePressEvent(event);
}
void MyButton::mouseReleaseEvent(QMouseEvent *event)
{
qDebug() << "MOUSE RELEASE!";
QPushButton::mouseReleaseEvent(event);
}
void MyButton::mouseMoveEvent(QMouseEvent *event)
{
qDebug() << "MOUSE MOVE!";
QPushButton::mouseMoveEvent(event);
}
To copy to clipboard, switch view to plain text mode
Which after a single click, output was:
MOUSE PRESS!
MOUSE MOVE!
MOUSE MOVE!
MOUSE MOVE!
MOUSE MOVE!
MOUSE MOVE!
MOUSE MOVE!
MOUSE PRESS!
MOUSE MOVE!
MOUSE MOVE!
MOUSE MOVE!
MOUSE MOVE!
MOUSE MOVE!
MOUSE MOVE!
To copy to clipboard, switch view to plain text mode
... etc, and NO "MOUSE RELEASE!" For that, I had to click a second time!
First, I tried adding in main.cpp on QApplication a:
a.setAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents);
a.setAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents);
To copy to clipboard, switch view to plain text mode
Secondly, at the widget level I tried:
ui->pushButton->setAttribute(Qt::WA_AcceptTouchEvents);
ui->pushButton->setAttribute(Qt::WA_AcceptTouchEvents);
To copy to clipboard, switch view to plain text mode
Neither of which seemed to help.
Now, in my production code, I found that for a QPushButton which opened a QDialog, I could trigger it on the "pressed" signal and after it's return, add:
QMouseEvent event
( QEvent::MouseButtonRelease, ui
->pushButton
->pos
(), Qt
::AllButtons,
0,
0 );
QMouseEvent event( QEvent::MouseButtonRelease, ui->pushButton->pos(), Qt::AllButtons, 0, 0 );
QApplication::sendEvent( ui->pushButton, &event );
To copy to clipboard, switch view to plain text mode
And that worked fine!
However, for the QPushButtons in my QDialog, I still have the problem of the buttons not providing a "release" after a "click".
Any insight would be greatly appreciated! (This is a cross-compiled Linux application on a device with a touch screen.)
Bookmarks