Qt3D中的QObjectPicker并设置PointPick不起作用

时间:2018-04-20 14:42:46

标签: python-3.x pyqt5 qt3d pyside2

我想使用点选择器在点云中拾取(获取)我的点的坐标。这就是我想将QPickingSettings设置为PointPicking的原因,但似乎无法完成。发送到方法mouse_event的事件属于QPickEvent类型而非QPickPointEvent类型。我做错了什么?

self.picker = Qt3DRender.QObjectPicker(self)
picking_settings = Qt3DRender.QPickingSettings(self.picker)
picking_settings.setFaceOrientationPickingMode(
    Qt3DRender.QPickingSettings.FrontAndBackFace)  
# set QObjectPicker to PointPicking:
picking_settings.setPickMethod(
    Qt3DRender.QPickingSettings.PointPicking)
picking_settings.setPickResultMode(
    Qt3DRender.QPickingSettings.NearestPick)
picking_settings.setWorldSpaceTolerance(.5)

self.picker.setHoverEnabled(True)
self.picker.setDragEnabled(True)

def mouse_event(e):
    # do something
    # e should be QPickPointEvent type
    pass

self.picker.moved.connect(mouse_event)
self.picker.pressed.connect(mouse_event)
self.picker.clicked.connect(mouse_event)
self.picker.released.connect(mouse_event)
self.addComponent(self.picker)

1 个答案:

答案 0 :(得分:1)

我不熟悉python API,但你不应该创建自己的QPickingSettings实例,而是使用作为QRenderSettings实例属性存在的实例(即单例)。

如果您正在使用Qt3DExtras中的Qt3DWindow,它将提供QRenderSettings实例的访问者。

否则,您需要创建QRenderSettings的实例并将其添加为实体的组件。按照惯例,我们倾向于使用场景图的根。