我在Linux上使用Qt 4。

我正在为触摸屏显示器实现应用程序,并且还插入了鼠标和键盘。

我可以实现鼠标或触摸屏,但不能实现两者,因为它们之间的交互很差。主要问题是,当我单击鼠标或按触摸屏时,会触发以下事件。

(注意:我重新实现了此功能,以便可以执行所需的操作)

MainWindow::mousePressEvent(QMouseEvent *ev)
{
    // Handle mouse specific events
}

但是,当我按下触摸屏时,也会触发相同的功能:(

因此,我无法区分单击鼠标和触摸屏! –如何解决这个问题?如何确定是单击鼠标还是触摸屏?

我尝试查看事件类型,但它始终为2(mouseClickEvent,但从未出现过TouchBegin或类似事件)。目前我被困在这里:(

编辑:

我对此进行了进一步研究,并实现了以下内容:
MainWindow::MainWindow(QWidget *parent)
{
...
    qApp->installEventFilter(this);
    setAttribute(Qt::WA_AcceptTouchEvents);
    setAttribute(Qt::WA_TouchPadAcceptSingleTouchEvents);
}
bool MainWindow::eventFilter(QObject *, QEvent * pEvent)
{
    switch(pEvent->type())
    {
    case QEvent::TouchBegin:
        qDebug("BEGIN");
        break;
    case QEvent::TouchUpdate:
        qDebug("UPDATE");
        break;
    case QEvent::TouchEnd:
        qDebug("END");
        break;
    case QEvent::MouseMove:
        qDebug("MOUSE");
        break;
   };
   return false;
}

我发现无论触摸屏输入还是鼠标输入,我总是会得到一个MouseMove事件。

我决定我的硬件设置必须使我的触摸屏像鼠标而不是触摸屏一样工作(如果可能的话)。所以我已经打印出我的/ dev / inputs /来查看:
root@dm814x-evm:/dev/input# ls -l
drwxr-xr-x    2 root     root          180 Jan  1  2000 by-id
drwxr-xr-x    2 root     root          180 Jan  1  2000 by-path
crw-r-----    1 root     root      13,  64 Jan  1  2000 event0
crw-r-----    1 root     root      13,  65 Jan  1  2000 event1
crw-r-----    1 root     root      13,  66 Jan  1  2000 event2
crw-r-----    1 root     root      13,  67 Jan  1  2000 event3
crw-r-----    1 root     root      13,  68 Jan  1  2000 event4
crw-r-----    1 root     root      13,  69 Jan  1  2000 event5
crw-r-----    1 root     root      13,  70 Jan  1  2000 event6
crw-r-----    1 root     root      13,  71 Jan  1  2000 event7
lrwxrwxrwx    1 root     root           69 May  1 08:11 keyboard -> /dev/input/by-id/usb-Cypress_WinCE_USB_Keyboard___PS2_Mouse-event-kbd
lrwxrwxrwx    1 root     root            6 Jan  1  2000 keypad -> event2
crw-r-----    1 root     root      13,  63 Jan  1  2000 mice
crw-r-----    1 root     root      13,  32 Jan  1  2000 mouse0
crw-r-----    1 root     root      13,  33 Jan  1  2000 mouse1
crw-r-----    1 root     root      13,  34 Jan  1  2000 mouse2
crw-r-----    1 root     root      13,  35 Jan  1  2000 mouse3
lrwxrwxrwx    1 root     root           67 May  1 08:11 touchscreen -> /dev/input/by-id/usb-eGalax_Inc._USB_TouchController-event-joystick

root@dm814x-evm:/dev/input/by-id# ls -l
lrwxrwxrwx    1 root     root            9 Jan  1  2000 usb-Cypress_WinCE_USB_Keyboard___PS2_Mouse-event-kbd -> ../event0
lrwxrwxrwx    1 root     root            9 Jan  1  2000 usb-Cypress_WinCE_USB_Keyboard___PS2_Mouse-event-mouse -> ../event1
lrwxrwxrwx    1 root     root            9 Jan  1  2000 usb-Cypress_WinCE_USB_Keyboard___PS2_Mouse-mouse -> ../mouse0
lrwxrwxrwx    1 root     root            9 Jan  1  2000 usb-eGalax_Inc._USB_TouchController-event-joystick -> ../event3
lrwxrwxrwx    1 root     root            9 Jan  1  2000 usb-eGalax_Inc._USB_TouchController-event-mouse -> ../event6
lrwxrwxrwx    1 root     root            9 Jan  1  2000 usb-eGalax_Inc._USB_TouchController-joystick -> ../mouse1
lrwxrwxrwx    1 root     root            9 Jan  1  2000 usb-eGalax_Inc._USB_TouchController-mouse -> ../mouse3

在我看来,触摸屏就像鼠标一样,因此只会产生鼠标事件。

现在这可能超出了该论坛的范围?

最佳答案

bool eventFilter(QObject * p_obj, QEvent * pevent)
{
  if (pevent->type() == QEvent::MouseButtonDblClick ||
   pevent->type() == QEvent::MouseButtonPress ||
   pevent->type() == QEvent::MouseButtonRelease ||
   pevent->type() == QEvent::Wheel)
  {
     QMouseEvent* pMouseEvent = dynamic_cast<QMouseEvent*>(pevent);
     if ((pMouseEvent != NULL) && (pMouseEvent->source() == Qt::MouseEventSource::MouseEventSynthesizedBySystem))
     {
         p_event->ignore();
         return true;
     }
  }
  return false;
 }

这肯定会解决您的问题。干杯
干杯!

10-08 11:40