【问题标题】:QML pointer handlers and handling grab changesQML 指针处理程序和处理抓取更改
【发布时间】:2021-11-18 20:12:14
【问题描述】:

在 Qt 5.10 中引入了Pointer Handlers。我试图在我的应用程序中使用这些而不是MouseArea。特别是,我使用的是DragHandler。我想确定何时开始拖动并收到抓取更改的通知。 Qt 提供了DragHandler::grabChanged(GrabTransition transition, EventPoint point)(参见here),所以在我的代码中我将其用作:

DragHandler{
    id: dragHandler
    onGrabChanged: {
    // how to use transition ???
    }
}

但是,GrabTransition 似乎没有实现,文档也没有提供任何关于这个枚举可以取什么值的线索。

【问题讨论】:

    标签: c++ qt qml qt5


    【解决方案1】:

    对于位于 PointerDevice 中的 QT 6.2 GrabTransition 枚举

     enum GrabTransition {
        GrabPassive = 0x01,
        UngrabPassive = 0x02,
        CancelGrabPassive = 0x03,
        OverrideGrabPassive = 0x04,
        GrabExclusive = 0x10,
        UngrabExclusive = 0x20,
        CancelGrabExclusive = 0x30,
    };
    

    所以它会是例如PointerDevice.GrabPassive

    【讨论】:

      【解决方案2】:

      令人惊讶的是,文档并没有真正解释这一点。从源代码中,我能够确定下面的代码。 cmets 直接来自源代码:

      DragHandler {
          onGrabChanged: {
              switch (transition) {
              case EventPoint.GrabPassive:
              case EventPoint.GrabExclusive:
                  break;
              case EventPoint.UngrabPassive:
              case EventPoint.UngrabExclusive:
                  break;
              case EventPoint.CancelGrabPassive:
              case EventPoint.CancelGrabExclusive:
                   // the grab was stolen by something else
                  break;
              case EventPoint.OverrideGrabPassive:
                  // Passive grab is still there, but we won't receive point updates right now.
                  // No need to notify about this.
                  break;
              }
          }
      }
      

      【讨论】:

      • 我确实也看过源代码,然后尝试了你的代码,但我总是得到这个:ReferenceError: EventPoint is not defined
      • 这很奇怪。我没有得到那个错误。您使用的是什么版本的 Qt?
      • 我使用的是 Qt 6.2rc,但是切换到 5.15 没有错误。虽然,似乎从未调用过 onGrabChanged 处理程序。我用onGrabChanged: console.debug("hello") 对其进行了测试,但 qml 没有输出任何内容。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多