Vtk With Qt5 - Timer Stops Running When Window Is Interacted With
I've been trying to do animation with VTK, so I've been using TimerEvent. When I tried to move over to the Qt binding, it broke. The problem is that as soon as I interact with the
Solution 1:
The problem is reproducible in Linux 16.04, VTK8.1.1 and Qt5.5.1.
As you are using Qt, a workaround for your problem is to use QTimer()
. It is a solution if you want to work with a timing.
This is your minimal example changing the TimerEvent
for QTimer()
:
import vtk
from vtk.qt.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor
from PyQt5 import Qt
from PyQt5.QtCore import QTimer
message = "tick"defonTimerEvent():
global message
print(message)
if message == "tick":
message = "tock"else:
message = "tick"
app = Qt.QApplication([])
mainWindow = Qt.QMainWindow()
renderer = vtk.vtkRenderer()
vtkWidget = QVTKRenderWindowInteractor(mainWindow)
vtkWidget.GetRenderWindow().AddRenderer(renderer)
mainWindow.setCentralWidget(vtkWidget)
vtkWidget.GetRenderWindow().GetInteractor().Initialize()
#timerId = vtkWidget.CreateRepeatingTimer(100)#vtkWidget.AddObserver("TimerEvent", onTimerEvent)
timer = QTimer()
timer.timeout.connect(onTimerEvent)
timer.start(100)
mainWindow.show()
app.exec_()
Post a Comment for "Vtk With Qt5 - Timer Stops Running When Window Is Interacted With"