[vtkusers] QVTKWidget in Python ?

Jothybasu Selvaraj jothybasu at gmail.com
Mon Nov 28 10:48:32 EST 2011


Here is the working code

import sys
from PyQt4 import QtCore, QtGui
from PyQt4.QtGui import *
from vtk.qt4.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor
import vtk

class MainWindow(QtGui.QMainWindow):
    def __init__(self, parent = None):
        super(MainWindow, self).__init__(parent)
        self.initUI()

    def initUI(self):
       widget = QVTKRenderWindowInteractor()
       widget.Initialize()
       widget.Start()
##       widget.AddObserver("ExitEvent", lambda o, e, a=app: a.quit())

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

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

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

       coneActor = vtk.vtkActor()
       coneActor.SetMapper(coneMapper)
       ren.AddActor(coneActor)
       widget.show()



if __name__ == "__main__":
    app=QApplication(sys.argv)
    form=MainWindow()
    app.exec_()

Jothy

On Mon, Nov 28, 2011 at 3:33 PM, chasank <chasank at gmail.com> wrote:

> What's the wrong with below script? It just shows a blank window, where is
> the interactor window?
> Can anyone help me?
>
> import sys
> from Nifti import Nifti
> from PyQt4 import QtCore, QtGui
> from PyQt4.QtGui import *
> from vtk.qt4.QVTKRenderWindowInteractor import QVTKRenderWindowInteractor
> import vtk
>
> class MainWindow(QtGui.QMainWindow):
>
>  def __init__(self, parent = None):
>    super(MainWindow, self).__init__(parent)
>    self.initUI()
>
>  def initUI(self):
>
>    widget = QVTKRenderWindowInteractor(self)
>    widget.Initialize()
>    widget.Start()
>    widget.AddObserver("ExitEvent", lambda o, e, a=app: a.quit())
>
>    ren = vtk.vtkRenderer()
>    widget.GetRenderWindow().AddRenderer(ren)
>
>    cone = vtk.vtkConeSource()
>    cone.SetResolution(24)
>
>    coneMapper = vtk.vtkPolyDataMapper()
>    coneMapper.SetInput(cone.GetOutput())
>
>    coneActor = vtk.vtkActor()
>    coneActor.SetMapper(coneMapper)
>    ren.AddActor(coneActor)
>    widget.show()
>
>    layout = QVBoxLayout()
>    layout.addWidget(widget)
>
>    central = QWidget()
>    central.setLayout(layout)
>
>    self.setCentralWidget(central)
>    self.setWindowTitle('Example')
>    self.show()
>
>
> --
> View this message in context:
> http://vtk.1045678.n5.nabble.com/QVTKWidget-in-Python-tp5024567p5029176.html
> Sent from the VTK - Users mailing list archive at Nabble.com.
> _______________________________________________
> 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
>



-- 
Jothy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20111128/b5f727ec/attachment.htm>


More information about the vtkusers mailing list