无法在 QQuickWindow 中接收精确的笔输入

Unable to receive precise pen input in a QQuickWindow

本文关键字:输入 QQuickWindow      更新时间:2023-10-16

我发现无法在 QML 中处理手写笔输入,所以我对QQuickWindow进行子类化,并在我的 QML 应用程序中将其设置为我的根窗口:

#ifndef TABLETWINDOW_H
#define TABLETWINDOW_H
#include <QObject>
#include <QQuickWindow>
class TabletWindow : public QQuickWindow
{
Q_OBJECT
public:
TabletWindow();
void tabletEvent(QTabletEvent* event) override{
qDebug() << event->posF();
}
#endif // TABLETWINDOW_H

调试输出显示平板电脑事件的位置没有双精度(例如 QPoint(200,300(。然后我用QMainWindow和Qt小部件测试了同样的东西:

class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(){}
void tabletEvent(QTabletEvent* event){
qDebug() << event->posF();
}
};

使用小部件的方法,事件确实具有双精度(因此更加精确(。我对此有点困惑,因为我认为QQuickWindowQMainWindow两个子类QWindow,因此它们的虚函数签名之间应该没有太大区别。 我已经在带有Qt 10的Windows 5.12上对此进行了测试

在对此进行调查后,我注意到使用QTabletEvent::highResGlobalXQTabletEvent::highResGlobalY我以双精度获得坐标。这是非常奇怪和烦人的,因为我不得不使用QWindow::mapFromGlobal,它只在QPoint上运行,所以我必须得到坐标的整数部分(使用std::modf(,然后构造传递一个QPoint并创建一个新的QPointF,加上坐标的小数部分。