【问题标题】:How to handle Stylus/Pen input in QML如何在 QML 中处理 Stylus/Pen 输入
【发布时间】:2020-03-29 14:04:40
【问题描述】:

我正在创建一个简单的绘图应用程序,并希望我的应用程序处理笔(Apple Pencil 之类的触控笔)输入。该应用程序是用 Qml/Qt Quick 编写的。我知道在使用 QWidgets 时,您可以使用 QTabletEvent (example) 处理平板电脑事件,但是如何在 QML 中处理笔输入(使用 MouseArea 不起作用,我也没有使用 PointHandler 运气)。有谁知道是否可以在 Qt Quick 中处理 Pen 输入?

【问题讨论】:

    标签: qt qml touch stylus-pen


    【解决方案1】:

    尝试使用 QML TapHandler:https://doc.qt.io/qt-5/qml-qtquick-taphandler.html

    acceptedDevices: PointerDevice.Mouse | PointerDevice.Stylus
    

    【讨论】:

    • TapHandlerPointHandler 不一样。我试过这个PointHandler { id: handler acceptedDevices: PointerDevice.TouchScreen | PointerDevice.Stylus }
    • 可能有些东西不能正常工作。我建议研究这个:github.com/dragly/hello-remarkable 在这里我可以看到一个处理tabletEvent 并发送给孩子class PaintedCanvas : public QQuickPaintedItemclass TabletWindow : public QQuickWindow
    • 这是一个非常有用的例子,谢谢。看来我需要子类化一个自定义 QQuickWindow 并从那里处理平板电脑事件。
    • Qt 开发人员似乎忘记实现平板电脑事件的处理程序(code 中有 TODO)
    • 5.15 即将发布,最终将让 TabletEvents 在 QML 周围正确传播。所以处理程序实际上可以最终限制在平板设备上。
    【解决方案2】:

    查看@Albertino80 链接的示例,我将QQuickWindow 子类化,它继承了QWindow,因此能够接收平板电脑事件(void tabletEvent(QTabletEvent* event)。然后这些事件可用于发出适当的信号可以传播到其他 QObjects。这种方法工作正常,但它的问题是事件坐标不是它们被消耗的项目的本地,而是必须通过将坐标映射到自定义窗口来手动重新计算每个事件的位置.

    【讨论】:

      猜你喜欢
      • 2010-12-21
      • 1970-01-01
      • 1970-01-01
      • 2020-03-16
      • 2014-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-30
      相关资源
      最近更新 更多