[vtkusers] embedded VTK window in PyQt application

John Vines jvines at arl.army.mil
Wed May 13 16:11:52 EDT 2009


Chris,
    Thanks but no luck??  I must be doing something wrong when building 
VTK?  I'm building with Qt 4.3.3, enabled VTK_USE_GUISUPPORT and 
building the QVTK widget/plugin.  Do you happen to have the 
CMakeCache.txt file for your build of VTK? 

Here are my errors on RHEL4 (x86_64) for the exercise3c.py example:
X Error: BadWindow (invalid Window parameter) 3
  Major opcode: 2 (X_ChangeWindowAttributes)
  Resource id:  0x1c00010
X Error: BadWindow (invalid Window parameter) 3
  Major opcode: 3 (X_GetWindowAttributes)
  Resource id:  0x1c00010
Segmentation fault (core dumped)

John

Chris Kees wrote:
> 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
> ------------------------------------------------------------------------
>
>
>
>
>
> 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