[vtkusers] embedded VTK window in PyQt application

Wylie, Brian bnwylie at sandia.gov
Wed May 13 11:32:08 EDT 2009


There's a gui.py example script in 

VTK\Examples\Infovis\Python\gui.py

written by Tim Shead, that may or may not be informative....  


  Brian Wylie - Org 1424
  Sandia National Laboratories
  MS 1323 - Building CSRI/242
  (505)844-2238 FAX(505)284-2518   
       _______ __
      /_  __(_) /_____ _____
       / / / / __/ __ `/ __ \
      / / / / /_/ /_/ / / / /
     /_/ /_/\__/\__,_/_/ /_/
            Informatics Toolkit

-----Original Message-----
From: vtkusers-bounces at vtk.org [mailto:vtkusers-bounces at vtk.org] On Behalf Of Chris Kees
Sent: Wednesday, May 13, 2009 8:58 AM
To: John Vines
Cc: vtkusers at vtk.org
Subject: Re: [vtkusers] embedded VTK window in PyQt application

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_())

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers





More information about the vtkusers mailing list