Qt 中的 Vedo Plotter - 鼠标单击事件未在正确位置注册

Vedo Plotter in Qt - Mouse Click Event not registering at the correct position

我已经尝试了几种不同的方法来解决鼠标点击在我的 Qt 主窗口中没有正确注册的问题。当仅使用我的 QHD 显示器时,该程序运行良好 (video). However, when using my laptop (zoomed in at 1792 x 1120) as the only display, the mouse clicks seemed to have a varying up-right offset and register more accurately near the bottom left corner of the widget (video)。我怀疑显示器的屏幕分辨率可能会导致 vedo 出现问题。

鼠标事件是 vedo 绘图仪事件。更改绘图仪的“screensize”、“size”、“pos”属性未能解决问题。

我查阅了 vedo 提供的一些示例,特别是 mousehover.py 和 qt_window1.py。鼠标悬停示例在我的笔记本电脑上运行良好。但是,在 qt_window1.py 中添加点击事件也会产生同样的问题。因此,问题很有可能是qt widget引起的。

def __init__(self,size):
    super(MainWindow, self).__init__()

    # load the components defined in th xml file
    loadUi("viewer_gui.ui", self)
    self.screenSize = size

    # Connections for all elements in Mainwindow
    self.pushButton_inputfile.clicked.connect(self.getFilePath)
    self.pushButton_clearSelection.clicked.connect(self.clearScreen)
    self.action_selectVertex.toggled.connect(self.actionSelection_state_changed)
    self.action_selectActor.toggled.connect(self.actionSelection_state_changed)

    # Set up VTK widget
    self.vtkWidget = QVTKRenderWindowInteractor()
    self.splitter_viewer.addWidget(self.vtkWidget)

    # ipy console
    self.ipyConsole = QIPythonWidget(customBanner="Welcome to the embedded ipython console\n")
    self.splitter_viewer.addWidget(self.ipyConsole)
    self.ipyConsole.pushVariables({"foo":43, "print_process_id":print_process_id, "ipy":self.ipyConsole, "self":self})
    self.ipyConsole.printText("The variable 'foo' and the method 'print_process_id()' are available.\
        Use the 'whos' command for information.\n\nTo push variables run this before starting the UI:\
            \n ipyConsole.pushVariables({\"foo\":43,\"print_process_id\":print_process_id})")

    # Create renderer and add the vedo objects and callbacks
    self.plt = Plotter(qtWidget=self.vtkWidget,bg='DarkSlateBlue',bg2='MidnightBlue',screensize=(1792,1120))
    self.id1 = self.plt.addCallback("mouse click", self.onMouseClick)
    self.id2 = self.plt.addCallback("key press",   self.onKeypress)
    self.plt.show()                  # <--- show the vedo rendering

def onMouseClick(self, event):
    if(self.action_selectActor.isChecked()):
        self.selectActor(event)
    elif(self.action_selectVertex.isChecked()):
        self.selectVertex(event)

def selectActor(self,event):
    if(not event.actor):
        return
    printc("You have clicked your mouse button. Event info:\n", event, c='y')
    printc("Left button pressed on", [event.picked3d])
    # adding a silhouette might cause some lags
    # self.plt += event.actor.silhouette().lineWidth(2).c('red')
    #an alternative solution
    self.actorSelection = event.actor.clone()
    self.actorSelection.c('red')
    self.plt += self.actorSelection

def selectVertex(self,event):
    if(not event.isPoints):
        return
    # print(arr[event.actor.closestPoint(event.picked3d, returnPointId=True)])
    printc("You have clicked your mouse button. Event info:\n", event, c='y')
    printc("Left button pressed on 3d: ", [event.picked3d])
    printc("Left button pressed on 2d: ", [event.picked2d])
    p = pointcloud.Point(pos=(event.picked3d[0],event.picked3d[1],event.picked3d[2]),r=12,c='red',alpha=0.5)
    self.vertexSelections.append(p)        
    self.plt += p

运行 以下行:

app = QApplication(sys.argv)
screen = app.primaryScreen()
print('Screen: %s' % screen.name())
size = screen.size()
print('Size: %d x %d' % (size.width(), size.height()))

输出:

Screen: Color LCD
Size: 1792 x 1120

原来是vtk的上游bug,与vedo无关。将 VTK 降级到 8.1.2 版并将 Python 降级到 3.7 后,运行 我笔记本电脑上的程序时点击问题消失了。其他人也遇到了同样的问题,这里是 vtk 网站上的一份 error 报告,描述了 vtkPropPicker 现在如何返回错误的世界坐标。