[PyQt] VTK in PyQt

Gib Bogle g.bogle at auckland.ac.nz
Tue Mar 9 07:58:43 GMT 2010


Perhaps someone will tell me what I'm doing wrong here.  I'm trying to create 
the render window for VTK programmatically, having given up on Qt Designer for 
the time being.  The following code can't be too badly wrong, because it 
generates no errors - but on the other hand it doesn't display the cone...

This is called after the QApplication is started and all the Qt widgets have 
been set up.


def QVTKRenderWidgetConeExample(self):
     """A simple example that uses the QVTKRenderWindowInteractor class."""

     # every QT app needs an app (not if called from ABM.pyw)
#    app = QtGui.QApplication(['QVTKRenderWindowInteractor'])

     # create the widget
     widget = QVTKRenderWindowInteractor()
     widget.Initialize()
     widget.Start()

     page_VTK = QtGui.QWidget()
     page_VTK.setObjectName("VTK display")
     layout = QtGui.QVBoxLayout(page_VTK)
     page_VTK.setLayout(layout)
     print "add the widget"
     layout.addWidget(widget)
     i = self.ui.stackedWidget.addWidget(page_VTK)
     print "added the widget: ",i

     ren = vtk.vtkRenderer()
     widget.GetRenderWindow().AddRenderer(ren)

     cone = vtk.vtkConeSource()
     cone.SetResolution(28)

     coneMapper = vtk.vtkPolyDataMapper()
     coneMapper.SetInput(cone.GetOutput())

     coneActor = vtk.vtkActor()
     coneActor.SetMapper(coneMapper)

     ren.AddActor(coneActor)

     # show the widget
     widget.show()
     print "show the widget"
     self.ui.stackedWidget.setCurrentIndex(i)
     time.sleep(5)
     # page_VTK does not get displayed.


More information about the PyQt mailing list