In Qt 5.10.1, why do I need to click twice on a QPushButton to get a release event?
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:
Code:
MyButton
::MyButton(QWidget *parent
) : {
}
{
qDebug() << "MOUSE PRESS!";
}
{
qDebug() << "MOUSE RELEASE!";
}
{
qDebug() << "MOUSE MOVE!";
}
Which after a single click, output was:
Code:
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:
Code:
a.setAttribute(Qt::AA_SynthesizeMouseForUnhandledTouchEvents);
Secondly, at the widget level I tried:
Code:
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:
Code:
QMouseEvent event
( QEvent::MouseButtonRelease, ui
->pushButton
->pos
(), Qt
::AllButtons,
0,
0 );
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.)
Re: In Qt 5.10.1, why do I need to click twice on a QPushButton to get a release even
Re: In Qt 5.10.1, why do I need to click twice on a QPushButton to get a release even
Thank you for your response. I read that question and the answer to it was very close to the first example code I provided. There was no mention, however, of the release event NOT happening with a single "click".
Re: In Qt 5.10.1, why do I need to click twice on a QPushButton to get a release even
What about:-
QAbstractButton Class
Inherited By:
QCheckBox, QPushButton, QRadioButton, and QToolButton
[override virtual protected] void QAbstractButton::keyReleaseEvent(QKeyEvent *e)
Added after 1 2 minutes:
Quote:
Originally Posted by
jimbo
What about:-
QAbstractButton Class
Inherited By:
QCheckBox, QPushButton, QRadioButton, and QToolButton
[override virtual protected] void QAbstractButton::keyReleaseEvent(QKeyEvent *e)
Shou;d have said:-
[override virtual protected] void QAbstractButton::mouseReleaseEvent(QMouseEvent *e)
Reimplemented from QWidget::mouseReleaseEvent().
Re: In Qt 5.10.1, why do I need to click twice on a QPushButton to get a release even
I found that installing an eventFilter on the QPushButton where I return false for Mouse Press/Release made it respond as expected!
Code:
{
if (event
->type
() == QEvent::MouseButtonPress) {
qDebug() << "MouseButtonPress";
return false;
}
else if (event
->type
() == QEvent::MouseMove) {
qDebug() << "MouseMove";
return false;
}
else if (event
->type
() == QEvent::MouseButtonRelease) {
qDebug() << "MouseButtonRelease";
return false;
}
else
{
return QObject::eventFilter(obj, event
);
}
}
And added in MainWindow:
Code:
auto myEvent = new MyEvent(this);
ui->pushButton->installEventFilter(myEvent);