@JoeCFD
In order to troubleshoot this problem, we write a very simple project(testDemo), which only contains a QMainWindow. when we touch the mainwindow, and trigger a new dialog from other exe at the same time, the touchevent of this simple project also don't work normally.
bool MainWindow::event(QEvent *event)
{
switch (event->type()) {
case QEvent::MouseButtonPress:
{
QMouseEvent* mouse = (QMouseEvent*)event;
gPos = mouse->localPos();
qDebug() << "[mousePress]"
<< (Qt::MouseEventSource)mouse->source()
<< (Qt::MouseButton)mouse->button()
<< gPos.rx() << gPos.ry()
<< event->spontaneous();
QMainWindow::mousePressEvent(mouse);
break;
}
case QEvent::MouseButtonRelease:
{
QMouseEvent* mouse = (QMouseEvent*)event;
gPos = mouse->localPos();
qDebug() << "[MouseRelease]"
<< (Qt::MouseEventSource)mouse->source()
<< (Qt::MouseButton)mouse->button()
<< gPos.rx() << gPos.ry()
<< event->spontaneous();
QMainWindow::mouseReleaseEvent(mouse);
break;
}
case QEvent::MouseMove:
{
QMouseEvent* mouse = (QMouseEvent*)event;
gPos = mouse->localPos();
qDebug() << "[MouseMove]"
<< (Qt::MouseEventSource)mouse->source()
<< (Qt::MouseButton)mouse->button()
<< gPos.rx() << gPos.ry()
<< event->spontaneous() << cnt2++;
QMainWindow::mouseMoveEvent(mouse);
break;
}
case QEvent::TouchBegin:
{
QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
qDebug() << "[TouchBegin] : " << (Qt::TouchPointStates)touchEvent->touchPointStates()
// << (QTouchDevice::DeviceType)touchEvent->device()->type()
0 << cnt++
<< touchEvent->touchPoints().count()
<< (Qt::TouchPointState)touchEvent->touchPoints().at(0).state()
<< event->spontaneous();
break;
// event->ignore();
// return true;
}
case QEvent::TouchUpdate:
{
QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
qDebug() << "[TouchUpdate] : "
// << (QTouchDevice::DeviceType)touchEvent->device()->type()
<< cnt++
<< (Qt::TouchPointState)touchEvent->touchPoints().at(0).state()
<< event->spontaneous();
break;
// return true;
}
case QEvent::TouchEnd:
{
QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
qDebug() << "[TouchEnd] : "
// << (QTouchDevice::DeviceType)touchEvent->device()->type()
<< cnt++
<< (Qt::TouchPointState)touchEvent->touchPoints().at(0).state()
<< event->spontaneous();
break;
// return true;
}
case QEvent::TouchCancel:
{
QTouchEvent *touchEvent = static_cast<QTouchEvent *>(event);
qDebug() << "[TouchCancel] : " << (QTouchDevice::DeviceType)touchEvent->device()->type() << cnt++;
break;
// return true;
}
case QEvent::FocusIn:
{
QFocusEvent *fcEvent = static_cast<QFocusEvent *>(event);
qDebug() <<"[focus in] : "<< (Qt::FocusReason)fcEvent->reason() ;
// QTouchEvent* event = new QTouchEvent(QEvent::ActivationChange);
// qApp->postEvent(qApp,event);
break;
}
case QEvent::FocusOut:
{
QFocusEvent *fcEvent = static_cast<QFocusEvent *>(event);
qDebug() <<"[focus out] : " << (Qt::FocusReason)fcEvent->reason() ;
break;
}
default:
// if(event->spontaneous()) {
// event->accept();
// return true;
// }
if(event->type() != QEvent::HoverMove && event->type() != QEvent::Move) {
qDebug() << (QEvent::Type)event->type() << event->spontaneous();
}
break;
}
return QMainWindow::event(event);
}
We have tried to print the event loop during this operation, we found that the first time we touch the testDemo, touchbegin, mousemove can be printed, and mouserelease event can be printed when we release our finger from the testDemo;
When we first touch the testDemo with one finger(finger1), and we trigger a new dialog from other exe(for example, click any tool bar of qtcreator ) with another finger(finger2).
This time we release finger2 first, touch the testDemo again, it can only print the mousemove with the same position of the last mousemove pos, and the touch event can not be worked normally until we unplug the docking station of Surface.
I have found the same question in this link
https://forum.qt.io/topic/135219/qt-widgets-not-responding-to-touch-event-sometimes.
There is still no issue how to solve this problem.
Do you have any suggestion on this question?
And thanks for your help~