我得到了这个动作的一个解决方案。由于 pyvista 是 vtk 的基础,所以我使用了 vtk 函数,它工作正常。如果有人找到更好的解决方案,请发布。
mouse=pv._vtk.vtkInteractorStyleTrackballCamera()
mouse.SetDefaultRenderer(plotter.ren_win.GetRenderers().GetFirstRenderer())
plotter.SetInteractorStyle(mouse)
def clicked(m,event):
try:
modifiers = QApplication.keyboardModifiers()
if modifiers==QtCore.Qt.ControlModifier:pass
else:
clickPos = m.GetInteractor().GetEventPosition()
picker = pv._vtk.vtkPointPicker()
picker.Pick(clickPos[0], clickPos[1],0, m.GetDefaultRenderer())
actor=picker.GetActor()
if actor!=None:print(actor)
m.OnLeftButtonDown()
except Exception as e:print(e)
mouse.AddObserver("LeftButtonPressEvent", clicked)
谢谢生物模式。我根据您的建议编辑了我的代码。它看起来更好
def clicked(event):
picker = pv._vtk.vtkPropPicker()
picker.PickProp(event[0], event[1],plotter.ren_win.GetRenderers().GetFirstRenderer())
actor=picker.GetActor()
if actor!=None:print(actor)
plotter.track_click_position(callback=clicked,side='left', viewport=True)