from __future__ import unicode_literals from PyQt4 import QtCore, QtGui, QtOpenGL from vtk.qt4.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor import sys import vtk class MainWindow(QtGui.QMainWindow): def __init__(self, parent=None): QtGui.QMainWindow.__init__(self, parent) self.frame = QtGui.QFrame() self.vl = QtGui.QVBoxLayout() self.vtkWidget = QVTKRenderWindowInteractor2(self.frame) self.vl.addWidget(self.vtkWidget) self.ren = vtk.vtkRenderer() self.vtkWidget.GetRenderWindow().AddRenderer(self.ren) self.iren = self.vtkWidget.GetRenderWindow().GetInteractor() self.iren.DebugOn() # Create source source = vtk.vtkSphereSource() source.SetCenter(0, 0, 0) source.SetRadius(5.0) # Create a mapper mapper = vtk.vtkPolyDataMapper() mapper.SetInputConnection(source.GetOutputPort()) # Create an actor actor = vtk.vtkActor() actor.SetMapper(mapper) self.ren.AddActor(actor) self.ren.ResetCamera() self.frame.setLayout(self.vl) self.setCentralWidget(self.frame) self.show() self.vtkWidget.GetRenderWindow().Render() self.vtkWidget.GetRenderWindow().SetOffScreenRendering(True) self.vtkWidget.GetRenderWindow().Render() self.vtkWidget.GetRenderWindow().SetOffScreenRendering(False) self.vtkWidget.GetRenderWindow().Render() self.iren.Initialize() if __name__ == "__main__": app = QtGui.QApplication(sys.argv) window = MainWindow() sys.exit(app.exec_())