[vtkusers] "Hello World" for QVTKWidget using PyQt and VTK in Python

Jothy jothybasu at gmail.com
Wed Nov 3 13:50:08 EDT 2010


Keep the messages on the list.

"""A simple example that uses the QVTKRenderWindowInteractor class."""

    # every QT app needs an app
    app = QtGui.QApplication(['QVTKRenderWindowInteractor'])

    # create the widget
    widget = QVTKRenderWindowInteractor()
    widget.Initialize()
    widget.Start()
    # if you dont want the 'q' key to exit comment this.
    widget.AddObserver("ExitEvent", lambda o, e, a=app: a.quit())

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

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

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

    coneActor = vtk.vtkActor()
    coneActor.SetMapper(coneMapper)

    ren.AddActor(coneActor)

    # show the widget
    widget.show()
    # start event processing
    app.exec_()

On Wed, Nov 3, 2010 at 5:41 PM, Prathamesh Kulkarni <
prathameshmkulkarni at gmail.com> wrote:

> Got it!  The ui file was corrupted due to some reason. Now I'll try the
> remaining steps you told me. Also, if you have a simple example using
> QVTKWidget or QVTKRenderWindowInteractor (with or without using Qt
> Designer), please forward it to me. I am learning to many things at the same
> time!
>
> Thanks,
> Prathamesh
>
>
> On Wed, Nov 3, 2010 at 12:30 PM, Prathamesh Kulkarni <
> prathameshmkulkarni at gmail.com> wrote:
>
>> I run it in windows cmd, and now I get this:
>>
>> pyuic4 -o ui_sampleui1.py sampleui1.ui
>>
>> Error in input file: not well-formed (invalid token): line 1, column 1
>>
>> On Wed, Nov 3, 2010 at 12:23 PM, Jothy <jothybasu at gmail.com> wrote:
>>
>>> Are you typing pyuic4 in windows command prompt or some where else. I
>>> mean the window you get by typing start->run->cmd
>>>
>>> you don't need to import pyqt4 before typing pyuic4
>>>
>>> Jothy
>>>
>>>
>>> On Wed, Nov 3, 2010 at 5:19 PM, Prathamesh Kulkarni <
>>> prathameshmkulkarni at gmail.com> wrote:
>>>
>>>> Yes, I have the batch file in site_packages/PyQt4. When I do:
>>>>
>>>> import PyQt4
>>>> >>> pyuic4 -o sampleui.ui ui_sampleui1.py
>>>>
>>>> I get:
>>>>
>>>>   File "<console>", line 1
>>>>     pyuic4 -o sampleui.ui ui_sampleui1.py
>>>>                      ^
>>>> SyntaxError: invalid syntax
>>>>
>>>> I have also tried full paths. Where am I going wrong?
>>>>
>>>> - Prathamesh
>>>>
>>>>
>>>> On Wed, Nov 3, 2010 at 12:10 PM, Jothy <jothybasu at gmail.com> wrote:
>>>>
>>>>> pyuic4 is a bat file. Go to command window and type pyuic4 -o inputfile
>>>>> outputfile.
>>>>>
>>>>> Jothy
>>>>>
>>>>> On Wed, Nov 3, 2010 at 5:07 PM, Prathamesh Kulkarni <
>>>>> prathameshmkulkarni at gmail.com> wrote:
>>>>>
>>>>>> Thank you! I will try this out. Currently, I cannot find pyuic4! I'll
>>>>>> try to write the .py files for the GUI.
>>>>>>
>>>>>> - Prathamesh
>>>>>>
>>>>>>
>>>>>> On Wed, Nov 3, 2010 at 11:33 AM, Jothy <jothybasu at gmail.com> wrote:
>>>>>>
>>>>>>> I have attacehd the latest version (hope so!) of QVTKWidget. Add it
>>>>>>> to your working dir and follow the tricks/steps  given below
>>>>>>>
>>>>>>> 1) In your form add a QFrame from designer where you want a
>>>>>>> QVTKWidget (let's say the object name is qvtkWidget1)
>>>>>>>
>>>>>>> 2)Run pyuic4 to generate (Form1).ui files to (ui_Form1).py files
>>>>>>>
>>>>>>> 3) Now add the line "import QVTKWidget as QVW " in the ui_Form1.py
>>>>>>> file, above the class definition
>>>>>>>
>>>>>>> 4) Actual trick is, replace *self. qvtkWidget1 = QFrame(parent) as
>>>>>>> self.qvtkWidget1=QVW.QVTKRenderWindowInteractor(parent)*
>>>>>>>
>>>>>>> 5) uncomment the lines which add style/border as it would say during
>>>>>>> run-time "no attribute found".
>>>>>>>
>>>>>>> Hope this helps!
>>>>>>>
>>>>>>> Jothy
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On Wed, Nov 3, 2010 at 4:03 PM, Prathamesh Kulkarni <
>>>>>>> prathameshmkulkarni at gmail.com> wrote:
>>>>>>>
>>>>>>>> Yes, I selected "Full". I get the QVTKRenderWindowInteractor. I
>>>>>>>> wanted to use the QVTKWidget since, I have used it earlier in my C++
>>>>>>>> projects. Never-the-less, is there any example demonstrating the use of
>>>>>>>> QQVTKRenderWindowInteractor? (I am completely new to Python) Can I promote a
>>>>>>>> QWidget to it, like I did for QVTKWidget through the Qt Designer?
>>>>>>>>
>>>>>>>> Thanks,
>>>>>>>> Prathamesh
>>>>>>>>
>>>>>>>>
>>>>>>>> On Wed, Nov 3, 2010 at 10:50 AM, Jothy <jothybasu at gmail.com> wrote:
>>>>>>>>
>>>>>>>>> If you are using python x,y you should have
>>>>>>>>> QVTKRenderWindowInteractor.py in
>>>>>>>>>
>>>>>>>>> C:\Python26\Lib\site-packages\vtk\qt4
>>>>>>>>>
>>>>>>>>> Did you select "Full" during installation of pythonx,y?
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Jothy
>>>>>>>>>
>>>>>>>>> On Wed, Nov 3, 2010 at 3:45 PM, Prathamesh Kulkarni <
>>>>>>>>> prathameshmkulkarni at gmail.com> wrote:
>>>>>>>>>
>>>>>>>>>> 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?
>>>>>>>>>>
>>>>>>>>>> - Prathamesh
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> On Wed, Nov 3, 2010 at 5:18 AM, Jothy <jothybasu at gmail.com>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
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>
>>>>>>>>
>>>>>>>
>>>>>>
>>>>>
>>>>
>>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20101103/93faba4a/attachment.htm>


More information about the vtkusers mailing list