[vtkusers] "Hello World" for QVTKWidget using PyQt and VTK in Python
Prathamesh Kulkarni
prathameshmkulkarni at gmail.com
Wed Nov 3 11:49:51 EDT 2010
Thank you for the quick example.
Quoting from my previous mail "I am using Python2.6 which comes with
Pythonxy package. So I do not build VTK separately. It comes with Pythonxy
too. Now, in the site_packages/vtk/qt I cannot find QVTKWidget. Also, in my
separate build of VTK (with VTK_WRAP_PYTHON set) I do not get QVTKWidget
iniside bin/wrapping/python/vtk/qt. Where can I get it from?"
When I run the example, I get the obvious error: 'AttributeError: 'module'
object has no attribute 'QVTKWidget'. Meanwhile, I will try to see if
QVTKRenderWindowInteractor works for me.
- Prathamesh
On Wed, Nov 3, 2010 at 8:52 AM, Eric E. Monson <emonson at cs.duke.edu> wrote:
> Hello Prathamesh,
>
> Yes, it would help us diagnose your problems if you tell us which version
> of VTK you are using, on what platform, and whether you built it yourself
> (with VTK_WRAP_PYTHON_SIP: ON, which is required for the Python wrapping of
> QVTKWidget).
>
> I've had some troubles with getting installed versions of VTK to work
> automatically with the SIP Python wrapped classes, so for now I just set my
> library path and pythonpath to directories in the build tree (this is with
> bash on OS X):
>
> export VTK_DIR=/Users/emonson/Programming/VTK_git/VTK/build
> export DYLD_LIBRARY_PATH=$DYLD_LIBRARY_PATH:${VTK_DIR}/bin
> export PYTHONPATH=$PYTHONPATH:${VTK_DIR}/bin:${VTK_DIR}/Wrapping/Python
>
> Once everything is built correctly and the paths are set, then import
> vtk.qvtk should work. I'll attach a simple example at the end in case you
> need a script example.
>
> Also, just in case you didn't know, there is still the older
> QVTKRenderWindowInteractor which can be used to add a VTK render window to a
> PyQt app without building the SIP Python wrappers -- it's limited in a
> couple ways, but basically works fine for many applications.
>
> Talk to you later,
> -Eric
>
> ------------------------------------------------------
> Eric E Monson
> Duke Visualization Technology Group
>
>
> # ==============================
> from PyQt4 import QtCore, QtGui
> import vtk
> import sys
>
> class Ui_MainWindow(object):
> def setupUi(self, MainWindow):
> MainWindow.setObjectName("MainWindow")
> MainWindow.resize(400, 400)
> self.centralWidget = QtGui.QWidget(MainWindow)
> self.gridlayout = QtGui.QGridLayout(self.centralWidget)
> self.vtkWidget = vtk.QVTKWidget(self.centralWidget)
> self.gridlayout.addWidget(self.vtkWidget, 0, 0, 1, 1)
> MainWindow.setCentralWidget(self.centralWidget)
>
> class SimpleView(QtGui.QMainWindow):
>
> def __init__(self, parent = None):
> QtGui.QMainWindow.__init__(self, parent)
> self.ui = Ui_MainWindow()
> self.ui.setupUi(self)
> widget = self.ui.vtkWidget
> ren = vtk.vtkRenderer()
> renwin = widget.GetRenderWindow()
> renwin.AddRenderer(ren)
> cone = vtk.vtkConeSource()
> mapper = vtk.vtkPolyDataMapper()
> mapper.SetInputConnection(cone.GetOutputPort())
> actor = vtk.vtkActor()
> actor.SetMapper(mapper)
> ren.AddViewProp(actor)
> ren.ResetCamera()
> if __name__ == "__main__":
>
> app = QtGui.QApplication(sys.argv)
> window = SimpleView()
> window.show()
> sys.exit(app.exec_())
>
>
> On Nov 3, 2010, at 6:18 AM, Jothy wrote:
>
> Which python bundle are you using and how are importing the QVTK?
>
> One easiest option is to add the QVTKWidget into your working directory and
> import.
>
> Jothy
>
> On Wed, Nov 3, 2010 at 3:45 AM, Prathamesh Kulkarni <
> prathameshmkulkarni at gmail.com> wrote:
>
>> Hello all,
>>
>> I want to create a GUI using PyQt4 and display a vtkImage inside it. For
>> that, I need to embed a QVTKWidget in my GUI. However, I get 'ImportError:
>> No module named qvtk' when I do import vtk.qvtk as given in
>> http://vtk.1045678.n5.nabble.com/about-vtk-python-bindings-and-Qt-td2841114i20.html. I am confused about how to get started with this and did not find examples
>> demonstrating this.
>>
>> Please point me to the steps for writing this "hello world".
>>
>> Thanks,
>> Prathamesh
>>
>> _______________________________________________
>> 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
>>
>>
> _______________________________________________
> 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
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20101103/de01b1c5/attachment.htm>
More information about the vtkusers
mailing list