Qt嵌入式触摸屏QMouseEvents未收到,直到MouseButtonRelease收到

Qt Embedded Touchscreen QMouseEvents Not Received Until MouseButtonRelease Received

本文关键字:直到 MouseButtonRelease 收到 嵌入式 触摸屏 QMouseEvents Qt      更新时间:2023-10-16

我在一个带有触摸屏的小型ARM嵌入式Linux设备上使用Qt 4.8.3。我用tslib配置了我的触摸屏,并对其进行了校准,因此在/etc/中有一个点状文件。我的触摸事件的位置工作得很好,但无论如何,我在鼠标按下或鼠标释放事件之前获得鼠标移动的QEvent。此外,在我将手指从触摸屏上移开之前,我不会得到任何鼠标相关事件。我需要正常的行为,即我按下触摸屏并立即接收鼠标下降事件,然后是我的移动事件(如果有的话),然后是当我抬起手指时鼠标释放事件。

So what I'm seeing from the point of view of events received when I pressed down and then release looks like:
50 SockAct <-- Received right at press down
           <-- NO Other events received until press released
           <-- Now release by lifting finger from screen
50 SockAct <-- Immediately received a 50 ( SockAct ) and the rest of the events below:
2          <-- 2 == mouse down
2          <-- 2 == mouse down
3          <-- 3 == mouse release / up
3          <-- 3 == mouse release / up
77         <-- 77 == redraw

我还尝试通过实现以下qw74filter来查看QWS服务器事件,以观察进入我的QApplication的QWS事件:

/// For investigation mouse events
#include <QWSServer>
#include <QWSMouseHandler>
#include <QWSEvent>
bool GUIApp::qwsEventFilter(QWSEvent *e)
{
    qDebug() << e->type;
    if(e->type == QWSEvent::Mouse) {
        QWSMouseHandler *curMouse = QWSServer::mouseHandler();
        qDebug() << "mouse position is: " << curMouse->pos();
    }
    return false;
    /*
    QWSEvent::NoEvent   0   No event has occurred.
    QWSEvent::Connected 1   An application has connected to the server.
    QWSEvent::Mouse 2   A mouse button is pressed or released, or the mouse cursor is moved. See also Qt for Embedded Linux Pointer Handling.
    */
}

现在,当我启动我的应用程序时,我看到触摸屏幕后相同的行为-即打印以下内容:

2 <-- Nothing is printed until I release my finger from the screen!
mouse position is:  QPoint(89,312) 
2 
mouse position is:  QPoint(89,312) 

正如你所看到的,当我松开我的手指时,我得到了2个事件,大概是按下并松开。

我在Linux的/dev/input/触摸屏设备上运行'evtest',当按下屏幕时,肯定会立即看到触屏事件。直到我抬起手指,我才得到鼠标释放事件,因此驱动程序的行为符合预期。当我按下时,也没有"重复"触地事件-它只是一次按下的一个事件,但行为正确。

我不知道为什么我看到我的行为。Qt和输入设备之间一定存在转换问题。

此外,如果我在处理我的MouseButtonRelease接收事件时添加了3毫秒的延迟,那么我就会得到应用程序如何工作的期望行为,但我仍然没有收到我的鼠标事件,直到我释放按键。我根本不应该添加延迟,我希望鼠标向下发生,然后是任何移动,最后依次发生鼠标向上事件

有谁知道如何解决这个问题或什么可能导致这个??非常感谢!

,

直到我真正抬起手指,我才看到下面的打印:

...
MOVE TYPE:  5 
"Mouse move (382,129)" 
MOUSE BUTTON PRESS TYPE:  2 
"Mouse Button Press (1)" 
MOUSE BUTTON RELEASE TYPE:  3 
"Mouse Button Release (1)" 
....

这是我的eventFilter,我检查我的应用程序中收到的事件:

////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Just for kicks print out the mouse position
if (event->type() == QEvent::MouseButtonPress)
{
    qDebug() << "MOUSE BUTTON PRESS TYPE: " << event->type();
    QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
    qDebug() << QString("Mouse Button Press (%1)").arg(mouseEvent->button());
}
if (event->type() == QEvent::MouseMove)
{
    qDebug() << "MOVE TYPE: " << event->type();
    QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
    qDebug() << QString("Mouse move (%1,%2)").arg(mouseEvent->globalX()).arg(mouseEvent->globalY());
}
if (event->type() == QEvent::MouseButtonRelease)
{
    qDebug() << "MOUSE BUTTON RELEASE TYPE: " << event->type();
    QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event);
    delay();
    qDebug() << QString("Mouse Button Release (%1)").arg(mouseEvent->button());
    //return true; // Gobble the event
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////

这是我的延迟函数:

void Monitor::delay()
{
    QTime dieTime = QTime::currentTime().addMSecs(3);
    while( QTime::currentTime() < dieTime )
    QCoreApplication::processEvents(QEventLoop::AllEvents, 100);
}

解决-我发现这个线程:https://github.com/kergoth/tslib/issues/10概述了同样的问题。这似乎是一个问题在Tslib与Atmel MXT Maxtouch驱动程序。注释掉ts.conf文件中的Variance模块解决了我的问题——我现在在触摸屏幕后立即得到鼠标按下事件。