mangoByte
30th May 2018, 19:11
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) :
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);
}
Which after a single click, output was:
MOUSE PRESS!
MOUSE MOVE!
MOUSE MOVE!
MOUSE MOVE!
MOUSE MOVE!
MOUSE MOVE!
MOUSE MOVE!
... 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_SynthesizeMouseForUnhandledT ouchEvents);
Secondly, at the widget level I tried:
ui->pushButton->setAttribute(Qt::WA_AcceptTouchEvents);
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 );
QApplication::sendEvent( ui->pushButton, &event );
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.)
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);
}
Which after a single click, output was:
MOUSE PRESS!
MOUSE MOVE!
MOUSE MOVE!
MOUSE MOVE!
MOUSE MOVE!
MOUSE MOVE!
MOUSE MOVE!
... 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_SynthesizeMouseForUnhandledT ouchEvents);
Secondly, at the widget level I tried:
ui->pushButton->setAttribute(Qt::WA_AcceptTouchEvents);
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 );
QApplication::sendEvent( ui->pushButton, &event );
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.)