-
-
Save samueljohn/3090097 to your computer and use it in GitHub Desktop.
VTK Qt/PySide Python example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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_()) |
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
Small test wheter vtk rendering from python works with PySide or PyQt (if PySide is not found).