嵌入式 Qt 鼠标指针不显示

Embedded Qt Mouse Pointer Not Showing Up

我遇到了一个有趣的问题。我发现有很多线程人们正在努力隐藏或摆脱嵌入式 Qt GUI 上的光标...但我正试图让光标 显示 在嵌入式 Qt GUI 上。

我继承了前段时间 'finished' 的一个项目,在该项目上做最多工作的人已经离开了。快进到今天,需要向这个功能性触摸屏 GUI 添加光标。系统 OS 是 Yocto Linux,它是 运行 帧缓冲区上的 Qt 5.4 应用程序。

我搜索了 Qt 代码,没有任何东西可以隐藏光标。我已将适当的 QT_QPA_FB_HIDECURSOR=0 环境变量添加到我的 Qt 启动脚本中。我已经尝试将 QCursor obejct 添加到 GUI。不幸的是 none 这些东西都在工作。使用 QCusor 有时我可以在屏幕上找到一个光标,但与触摸输入无关(光标显示在我以编程方式将其移动到的位置,但当我与 GUI 交互时它会停留在那里) .

我的触摸输入事件绑定到 Qt(通过 QT_QPA_GENERIC_PLUGINS=evdevtouch 和 QT_QPA_EVDEV_TOUCHSCREEN_PARAMETERS=/dev/input/event9:rotate=180),但由于某些原因无法绑定触摸输入到光标。

至此,我花了几天时间处理环境变量和启动脚本修改,但我所做的一切都没有得到我想要的结果。

有没有人知道在哪里可以找到这个问题的解决方案?

谢谢! 伊恩

我不知道这是否适用于您的问题(我不使用 QT),但是有一个

HAVE_TOUCHSCREEN=1 变量在 machconfig 文件中。它通常位于 recipes-bsp/formfactor/formfactor 目录中的 BSP 层中。 将此设置为 1 会使光标不可见。

尝试将其设置为 0

所以,现在 3 个月后,我认为我的团队和我刚刚想出了一个可以解决这个问题的解决方案。

通往解决方案的道路始于 "Using libinput" 上的 Qt Documentation。该文档归结为几个重要的声明:

Parameters like the device node name can be set in the environment variables QT_QPA_EVDEV_MOUSE_PARAMETERS, QT_QPA_EVDEV_KEYBOARD_PARAMETERS and QT_QPA_EVDEV_TOUCHSCREEN_PARAMETERS


The mouse cursor shows up whenever QT_QPA_EGLFS_HIDECURSOR (for eglfs) or QT_QPA_FB_HIDECURSOR (for linuxfb) is not set and Qt's libudev-based device discovery reports that at least one mouse is available. When libudev support is not present, the mouse cursor always show up unless explicitly disabled via the environment variable.


The evdevtablet plugin provides basic support for Wacom and similar, pen-based tablets. It generates QTabletEvent events only. To enable it, pass QT_QPA_GENERIC_PLUGINS=evdevtablet in the environment or, alternatively, pass -plugin evdevtablet argument on the command-line. The plugin can take a device node parameter, for example QT_QPA_GENERIC_PLUGINS=evdevtablet:/dev/event1, in case the Qt's automatic device discovery (based either on libudev or a walkthrough of /dev/input/event*) is not functional or misbehaving.


因此,在我的系统中我有设备节点:event0event1event2, event3, event4, event5, mice,和 mouse0。因为我试图让 mouse 工作,所以我假设我必须使用 mouse0 节点。这导致我设置了这些环境变量:

QT_QPA_GENERIC_PLUGINS=evdevmouse
QT_QPA_EVDEV_MOUSE_PARAMETERS=/dev/input/mouse0

令我沮丧的是,这些环境变量没有任何结果。一段时间后,我和我的团队想出了如何从我们系统上的 Qt 源代码获取调试输出:

  • 修改我们yocto构建下的qtbase目录下的源代码(大致/yocto/poky/build/tmp/work/临时构建目录/qtbase
  • 正在将 qtbase/plugins/generic/libqevdevmouseplugin.so 复制到我的硬件(大约 /usr/lib/qt5/plugins/generic)
  • 运行 来自命令行的 Qt

我们很快发现来自mouse0mice的输入事件基本上是垃圾数据。在我们的系统上,我们确实在内核中设置了 EVDEV,因此鼠标输入也绑定到设备节点 event0。当我们尝试将 Qt 鼠标参数设置为 event0 时,我们开始看到看起来像真实数据的调试输出。

QT_QPA_GENERIC_PLUGINS=evdevmouse
QT_QPA_EVDEV_MOUSE_PARAMETERS=/dev/input/event0

但是,没有鼠标指针的问题仍然存在。过了一会儿,我们回顾了 Qt 文档,特别是上面列出的第 2 段。作为最后的尝试,我们尝试添加 QT_QPA_FB_HIDECURSOR 环境变量...

QT_QPA_GENERIC_PLUGINS=evdevmouse
QT_QPA_EVDEV_MOUSE_PARAMETERS=/dev/input/event0
QT_QPA_FB_HIDECURSOR=0

还有……瞧!经过无数小时的调试和阅读文档,我们终于得到了鼠标指针。

我认为我们问题的主要症结在于误解了 Qt 文档。

The mouse cursor shows up whenever ... QT_QPA_FB_HIDECURSOR (for linuxfb) is not set

通过 "not set",Qt 意味着明确定义为 FALSE...根本不只是 "not set"。

这个解决方案对我们有用,但至少有一点需要改进。一路上我偶然发现了 this thread answer on the Unix StackEx which points to the Kernel documentation of input/input.txt。在“3.2.2 mousedev”部分,您可以看到以下行:

Each 'mouse' device is assigned to a single mouse or digitizer, except the last one - 'mice'. This single character device is shared by all mice and digitizers, and even if none are connected, the device is present. This is useful for hotplugging USB mice, so that programs can open the device even when no mice are present.

这对我们来说意味着虽然我们可以使用 event0(当我们拔下鼠标时它会消失)来处理鼠标输入事件,但我们将无法支持热插拔,无需进行一些 kernel/Qt-source 修改或弄清楚如何让 mice 作为 Qt 鼠标输入参数工作。

所以,"why does event0 work and not mouse0/mice" 的问题仍然存在...但是现在我们已经找到了可以接受的解决方案。

更新:稍后我们发现 udev 在我们的系统上无法正常工作。我们将 udev 添加到 Yocto 构建包组的 RDEPENDS 中,现在我们可以设置

QT_QPA_GENERIC_PLUGINS=evdevmouse

我们得到了一个支持热插拔的工作鼠标指针。