Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
VTK Qt/PySide Python example
"""
A simple example that uses the QVTKRenderWindowInteractor
class.
"""
try:
from PySide import QtCore, QtGui
except ImportError:
try:
from PyQt4 import QtCore, QtGui
except ImportError as err:
raise ImportError("Cannot load either PyQt or PySide")
if __name__ == '__main__':
# every QT app needs an app
app = QtGui.QApplication(['QVTKRenderWindowInteractor'])
# create the widget
widget = QVTKRenderWindowInteractor()
widget.Initialize()
widget.Start()
# if you dont want the 'q' key to exit comment this.
widget.AddObserver("ExitEvent", lambda o, e, a=app: a.quit())
ren = vtk.vtkRenderer()
widget.GetRenderWindow().AddRenderer(ren)
cone = vtk.vtkConeSource()
cone.SetResolution(8)
coneMapper = vtk.vtkPolyDataMapper()
coneMapper.SetInputConnection(cone.GetOutputPort())
coneActor = vtk.vtkActor()
coneActor.SetMapper(coneMapper)
ren.AddActor(coneActor)
widget.SetPicker(vtk.vtkPointPicker())
# show the widget
widget.show()
# start event processing
sys.exit(app.exec_())
@samueljohn

This comment has been minimized.

Copy link
Owner Author

@samueljohn samueljohn commented Jul 11, 2012

Small test wheter vtk rendering from python works with PySide or PyQt (if PySide is not found).

@sugeerth

This comment has been minimized.

Copy link

@sugeerth sugeerth commented Jun 28, 2016

PySide version does not work

python2.7/site-packages/vtk/qt/QVTKRenderWindowInteractor.py", line 204, in init
QWidget.init(self, parent, wflags|Qt.MSWindowsOwnDC)
TypeError: QWidget(QWidget parent=None, Qt.WindowFlags flags=0): argument 1 has unexpected type 'PySide.QtGui.QFrame'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment