[vtkusers] Fwd: QVTKWidget in Python ?
Jothybasu Selvaraj
jothybasu at gmail.com
Mon Nov 28 11:03:47 EST 2011
---------- Forwarded message ----------
From: Adam Stylinski <stylinae at mail.uc.edu>
Date: Mon, Nov 28, 2011 at 3:59 PM
Subject: Re: [vtkusers] QVTKWidget in Python ?
To: Jothybasu Selvaraj <jothybasu at gmail.com>
On Mon, Nov 28, 2011 at 10:48 AM, Jothybasu Selvaraj <jothybasu at gmail.com>wrote:
> 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
>
>
> _______________________________________________
> 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
>
>
Ah, guess you were missing the QT event loop. The way to use python
bindings+QT bindings with VTK may very well be different from C++. Strange
that you had any window at all without app.exec().
My stent with PyQt was pretty brief.
--
Jothy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20111128/75372b3c/attachment.htm>
More information about the vtkusers
mailing list