[vtkusers] QVTKWidget mouse event in python

Nicola Creati ncreati at inogs.it
Fri Sep 17 11:37:03 EDT 2010


Hello,
thank you Clinton I works! Just a question is it possible to pass 
arguments to the 'myslot' SLOT? and how?

Nicola

Clinton Stimpson wrote:
> You just need to do the following to keep the objects from going out of scope
> self.connections = vtk.vtkEventQtSlotConnect()
> self.t = TestConnection()
>
> Clint
>
> On Friday, September 17, 2010 08:22:48 am Nicola Creati wrote:
>   
>> Hello,
>> I tried to use vtkEventQtSlotConnect but it does not work in my code. I
>> wrote a small example that showes what I'm trying to do.
>>
>> Nicola
>>
>> import vtk
>> from PyQt4.QtGui import *
>> from PyQt4.QtCore import *
>> import sys
>>
>> class TestConnection(QObject):
>>   @pyqtSlot()
>>   def myslot(self):
>>     print 'event'
>>
>> class MainWindow(QMainWindow):
>>   def __init__(self, parent=None):
>>     super(MainWindow, self).__init__(parent)
>>
>>     # Add the vtk window rwi
>>     self.qvtk = vtk.QVTKWidget()
>>     self.ren = vtk.vtkRenderer()
>>
>>     self.rw = vtk.vtkRenderWindow()
>>     self.rw.AddRenderer(self.ren)
>>     self.qvtk.SetRenderWindow(self.rw)
>>
>>     self.setCentralWidget(self.qvtk)
>>
>>     connections = vtk.vtkEventQtSlotConnect()
>>     t = TestConnection()
>>     connections.Connect(self.qvtk.GetInteractor().GetInteractorStyle(),
>>                                       vtk.vtkCommand.MouseMoveEvent,
>>                                       t,
>>                                       SLOT('myslot()'), "", 0.0,
>> Qt.AutoConnection)
>>
>> if __name__ == "__main__":
>>   app = QApplication(sys.argv)
>>   w = MainWindow()
>>   w.show()
>>   app.exec_()
>>
>> Eric E. Monson wrote:
>>     
>>> Hey Nicola,
>>>
>>> I haven't used this myself, so hopefully someone else can also help with
>>> more details, but I think what you need to use is vtkEventQtSlotConnect:
>>>
>>> http://www.vtk.org/doc/nightly/html/classvtkEventQtSlotConnect.html
>>>
>>> On that page there are links to two examples (C++) and a test (Python).
>>> The Python test is pretty minimal, so you'll probably have to look at
>>> those cxx tests to get more ideas of how to use it. I think the Qt
>>> events example in [vtk_src]/Examples/GUI/Qt/Events/GUI4.cxx will be most
>>> useful.
>>>
>>> Good luck,
>>> -Eric
>>>
>>> ------------------------------------------------------
>>> Eric E Monson
>>> Duke Visualization Technology Group
>>>
>>> On Sep 17, 2010, at 6:52 AM, Nicola Creati wrote:
>>>       
>>>> Hello,
>>>> I'm using the new QVTKWidget wrapped in python and I need to capture
>>>> mouse events. If I add an observer to the interactor style I can easly
>>>> capture any mouse event. On the Qt side I cannot get any mouse events
>>>> occurring in my QVTKWidgets. Is there a way to get it?
>>>>
>>>> Thanks.
>>>>
>>>> Nicola
>>>>
>>>>
>>>> _____________________________________________________________________
>>>> This communication, that may contain confidential and/or legally
>>>> privileged information, is intended solely for the use of the intended
>>>> addressees. Opinions, conclusions and other information contained in
>>>> this message, that do not relate to the official business of OGS, shall
>>>> be considered as not given or endorsed by it. Every opinion or advice
>>>> contained in this communication is subject to the terms and conditions
>>>> provided by the agreement governing the engagement with such a client.
>>>> Any use, disclosure, copying or distribution of the contents of this
>>>> communication by a not-intended recipient or in violation of the
>>>> purposes of this communication is strictly prohibited and may be
>>>> unlawful. For Italy only: Ai sensi del D.Lgs.196/2003 - "T.U. sulla
>>>> Privacy" si precisa che le informazioni contenute in questo messaggio
>>>> sono riservate ed a uso esclusivo del destinatario.
>>>> _____________________________________________________________________
>>>> _______________________________________________
>>>> 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
>
>   


-- 
Nicola Creati
Istituto Nazionale di Oceanografia e di Geofisica Sperimentale - OGS www.inogs.it Dipartimento di Geofisica della Litosfera Geophysics of Lithosphere Department CARS (Cartography and Remote Sensing) Research Group http://www.inogs.it/Cars/ Borgo Grotta Gigante 42/c 34010 Sgonico - Trieste - ITALY ncreati at ogs.trieste.it
off.   +39 040 2140 213
fax.   +39 040 327307

_____________________________________________________________________
This communication, that may contain confidential and/or legally privileged information, is intended solely for the use of the intended addressees. Opinions, conclusions and other information contained in this message, that do not relate to the official business of OGS, shall be considered as not given or endorsed by it. Every opinion or advice contained in this communication is subject to the terms and conditions provided by the agreement governing the engagement with such a client. Any use, disclosure, copying or distribution of the contents of this communication by a not-intended recipient or in violation of the purposes of this communication is strictly prohibited and may be unlawful. For Italy only: Ai sensi del D.Lgs.196/2003 - "T.U. sulla Privacy" si precisa che le informazioni contenute in questo messaggio sono riservate ed a uso esclusivo del destinatario.
_____________________________________________________________________ 




More information about the vtkusers mailing list