2

我在带有触摸屏的小型 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

我还尝试通过实现以下 qwsEventFilter 来查看 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/touchscreen 设备上运行了“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);
}
4

1 回答 1

1

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

于 2013-01-15T19:06:53.720 回答