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

huangapple go评论87阅读模式
英文:

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();
    }

};

使用小部件方法时,事件具有双精度(因此更精确)。我对此感到有些困惑,因为我以为QQuickWindowQMainWindow都是子类化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 &lt;QObject&gt;
#include &lt;QQuickWindow&gt;

class TabletWindow : public QQuickWindow
{
    Q_OBJECT
public:
    TabletWindow();
    void tabletEvent(QTabletEvent* event) override{
        qDebug() &lt;&lt; event-&gt;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() &lt;&lt; event-&gt;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::highResGlobalXQTabletEvent::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.

huangapple
  • 本文由 发表于 2020年1月3日 23:21:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/59581089.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定