[vtkusers] embedded VTK window in PyQt application

John Vines (CISD/HPCD) jvines at arl.army.mil
Wed May 13 13:18:44 EDT 2009


Chris,
    Thanks for the response.  Yes, I tried embedding the VTK window in a 
QFrame too but it core dumps on my RHEL4 box?  I tried your updated 
script and it has the same result.  What OS are you on?

Thanks again,
John

Chris Kees wrote:
> Hey John,
>
> I had a similar problem and ended  up putting the 
> QVTKRenderWindowInteractor in a Frame. I don't have a rational 
> explanation. I've included a modified version of your test script.
>
> Chris
> #!/usr/bin/env python
>
> import sys
> import vtk
> from vtk.qt4.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor
> from PyQt4 import Qt
> from PyQt4 import QtGui
> class test(Qt.QMainWindow):
>     """Test class"""
>     def __init__(self, parent=None):
>         Qt.QMainWindow.__init__(self, parent)
>         self.setWindowTitle(self.tr("PyQt4 VTK test"))
>         self.workspace = Qt.QWorkspace()
>         self.setCentralWidget(self.workspace)
>         self.frame = QtGui.QFrame(self.workspace)
>         self.hbox = QtGui.QHBoxLayout()
>         # create the widget
>         self.widget = QVTKRenderWindowInteractor(self.frame)
>         self.widget.Initialize()
>         self.widget.Start()
>         # if you dont want the 'q' key to exit comment this.
>         self.widget.AddObserver("ExitEvent", lambda o, e, a=app: 
> a.quit())
>         self.cone = vtk.vtkConeSource()
>         self.cone.SetResolution(8)
>         self.coneMapper = vtk.vtkPolyDataMapper()
>         self.coneMapper.SetInput(self.cone.GetOutput())
>         self.coneActor = vtk.vtkActor()
>         self.coneActor.SetMapper(self.coneMapper)
>         self.ren = vtk.vtkRenderer()
>         self.ren.AddActor(self.coneActor)
>         self.renWin=self.widget.GetRenderWindow()
>         self.renWin.AddRenderer(self.ren)
>         self.hbox.addWidget(self.widget)
>         self.frame.setLayout(self.hbox)
>         self.workspace.addWindow(self.frame)
>
> if __name__ == "__main__":
>     app = Qt.QApplication(sys.argv)
>     mainwindow = test()
>     mainwindow.show()
>     sys.exit(app.exec_())
>
> On May 13, 2009, at 8:04 AM, John Vines (CISD/HPCD) wrote:
>
>> #!/usr/bin/env python
>>
>> import sys
>> import vtk
>> from vtk.qt4.QVTKRenderWindowInteractor import 
>> QVTKRenderWindowInteractor
>> from PyQt4 import Qt
>>
>> class test(Qt.QMainWindow):
>>   """Test class"""
>>   def __init__(self, parent=None):
>>       Qt.QMainWindow.__init__(self, parent)
>>       self.setWindowTitle(self.tr("PyQt4 VTK test"))
>>             self.workspace = Qt.QWorkspace()
>>       self.setCentralWidget(self.workspace)
>>
>>       # create the widget
>>       self.widget = QVTKRenderWindowInteractor()
>>       self.widget.Initialize()
>>       self.widget.Start()
>>
>>       # if you dont want the 'q' key to exit comment this.
>>       self.widget.AddObserver("ExitEvent", lambda o, e, a=app: a.quit())
>>         self.ren = vtk.vtkRenderer()
>>       self.widget.GetRenderWindow().AddRenderer(self.ren)
>>         self.cone = vtk.vtkConeSource()
>>       self.cone.SetResolution(8)
>>             self.coneMapper = vtk.vtkPolyDataMapper()
>>       self.coneMapper.SetInput(self.cone.GetOutput())
>>             self.coneActor = vtk.vtkActor()
>>       self.coneActor.SetMapper(self.coneMapper)
>>         self.ren.AddActor(self.coneActor)
>>       self.workspace.addWindow(self.widget)
>>
>> if __name__ == "__main__":
>>   app = Qt.QApplication(sys.argv)
>>   mainwindow = test()
>>   mainwindow.show()
>>   sys.exit(app.exec_())
>




More information about the vtkusers mailing list