[vtkusers] embedded VTK window in PyQt application

Chris Kees christopher.e.kees at usace.army.mil
Wed May 13 15:05:07 EDT 2009


John,

I ran on Mac OS X 10.5.6 and CentOS 5 (x86_64), which I think is   
equivalent to RHEL5. My vtk/qt configuration is non-standard (Qt  
4.5.1, vtk-5.5), but I'm pretty sure that script should run. I've  
attached an old one of mine that ran fine under a "supported" vtk/qt/ 
python configuration.

Chris
-------------- next part --------------
A non-text attachment was scrubbed...
Name: exercise3c.py
Type: text/x-python-script
Size: 2755 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20090513/0c0d0be5/attachment.bin>
-------------- next part --------------


On May 13, 2009, at 12:18 PM, John Vines (CISD/HPCD) wrote:

> 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