英文:
Unable to receive precise pen input in a QQuickWindow
问题
我找不到在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();
}
};
使用小部件方法时,事件具有双精度(因此更精确)。我对此感到有些困惑,因为我以为QQuickWindow
和QMainWindow
都是子类化QWindow
,因此它们的虚拟函数签名之间不应该有太大的区别。我在Windows 10上使用Qt 5.12进行了测试。
英文:
I found no way to handle stylus input in QML so I subclass a QQuickWindow
and set it as my root window in my QML app:
#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
The debug output shows that the positions of the tablet events have no double precision (e.g QPoint(200,300). Then I tested the same thing using QMainWindow
and Qt widgets:
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(){}
void tabletEvent(QTabletEvent* event){
qDebug() << event->posF();
}
};
With the widgets approach the event do have double precision (and hence are much more precise). I am a bit confused by this since I thought QQuickWindow
and QMainWindow
both subclass QWindow
and hence there shouldn't be much difference between their virtual function signatures.
I have tested this on Windows 10 with Qt 5.12
答案1
得分: 1
在调查后,我注意到使用 QTabletEvent::highResGlobalX
和 QTabletEvent::highResGlobalY
可以获得双精度的坐标。这非常奇怪和让人讨厌,因为我不得不使用 QWindow::mapFromGlobal
,而该函数只对 QPoint
进行操作,所以我必须获取坐标的整数部分(使用 std::modf
),然后构建一个 QPoint 并创建一个新的 QPointF,将坐标的小数部分相加。
英文:
After investigating this, I notice that using QTabletEvent::highResGlobalX
and QTabletEvent::highResGlobalY
I get the coordinates with double precision. This is very strange and annoying since I had to use QWindow::mapFromGlobal
, which only operates on QPoint
, so I had to get the integer parts of the coordinates (using std::modf
) and then construct pass a QPoint and create a new QPointF with the addition of the fractional parts of the coordinates.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论