Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save fmorency/2911801 to your computer and use it in GitHub Desktop.
Save fmorency/2911801 to your computer and use it in GitHub Desktop.
QVTKRenderWindowInteractor
import vtk
from vtk.qt4.QVTKRenderWindowInteractor import *
from PySide.QtCore import *
from PySide.QtGui import *
from PySide.QtXml import *
from PySide.QtUiTools import *
if __name__ == "__main__":
app = QApplication(['QVTKRenderWindowInteractor'])
w, h = 400, 400
main_window = QMainWindow()
grid_layout = QGridLayout()
button_test = QPushButton('Dummy')
#VTK renderer
ren = vtk.vtkRenderer()
ren.SetBackground(0.1, 0.1, 0.2)
#Cone source
cone = vtk.vtkConeSource()
cone.SetResolution(8)
coneMapper = vtk.vtkPolyDataMapper()
coneMapper.SetInputConnection(cone.GetOutputPort())
coneActor = vtk.vtkActor()
coneActor.SetMapper(coneMapper)
#Add cone source to renderer
ren.AddActor(coneActor)
# Rendering window
renWin = vtk.vtkRenderWindow()
renWin.AddRenderer(ren)
renWin.SetSize(w,h)
#Qt Window Interactor
axial_view = QVTKRenderWindowInteractor(rw=renWin, width=w, height=h)
axial_view.Initialize()
axial_view.Start()
axial_view.SetPicker(vtk.vtkPointPicker())
#Comment the next line to render the QVTKRenderWindowInteractor in its own
#window
grid_layout.addWidget(axial_view)
grid_layout.addWidget(button_test, 0, 1)
main_window.setCentralWidget(QWidget())
main_window.centralWidget().setLayout(grid_layout)
#Render VTK
renWin.Render()
axial_view.Render()
#Show Qt widgets
axial_view.show()
main_window.show()
app.exec_()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment