I made a simple app to track the number of clicks.
Everything works fine and the number of clicks is printed as expected, but the observer stops working after performing double clicks.
How can i solve this issue?
from PySide2 import QtWidgets
import pyvista as pv
import pyvistaqt
from vtkmodules.vtkInteractionStyle import vtkInteractorStyleTrackballCamera
import sys
class MainWindow(QtWidgets.QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.frame = QtWidgets.QFrame()
vlayout = QtWidgets.QVBoxLayout()
self.vtk_widget = pyvistaqt.QtInteractor(self.frame)
style = MyStyle()
self.vtk_widget.interactor.SetInteractorStyle(style)
vlayout.addWidget(self.vtk_widget)
self.frame.setLayout(vlayout)
self.setCentralWidget(self.frame)
sphere = pv.Sphere()
self.vtk_widget.add_mesh(sphere)
class MyStyle(vtkInteractorStyleTrackballCamera):
def __init__(self):
super().__init__()
self.click_number = 0
self.AddObserver("LeftButtonPressEvent", self.left_button_press_event)
def left_button_press_event(self, obj, event):
self.click_number += 1
print(self.click_number)
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
window = MainWindow()
window.show()
sys.exit(app.exec_())