Re: [PyQt] Signal this way

2009-09-29 Thread David Boddie
On Tue Sep 29 02:47:11 BST 2009, pantheon wrote:

> I am creating  in a loop and adding it to menu.
>
> action = QtGui.QAction(QtGui.QIcon(iconFile), fileName, menu)
>menu.addAction(action)
>
> I need to connect this action to a python function in such a way that I
> should get  of QAction or instance of QAction object itself.

Connect its triggered() signal to a slot where you call sender() to obtain
the action object.

New-style connection syntax:

  action.triggered.connect(handleAction)

Then you can obtain the text from the action object:

  def handleAction(self):
  text = sender().text()

David
___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt


[PyQt] Signal this way

2009-09-28 Thread pantheon

Hi,

I am creating  in a loop and adding it to menu.
   

action = QtGui.QAction(QtGui.QIcon(iconFile), fileName, menu)
menu.addAction(action)


I need to connect this action to a python function in such a way that I
should get  of QAction or instance of QAction object itself.
Python function:

If action name is required

def contextMenuAction(self, actionName):
print actionName


If action object is required

def contextMenuAction(self, actionObject):
myData = actionObject.data()



How do I setup action and slot? Logically it would be like this:

self.connect(action, QtCore.SIGNAL("triggered()"), self,
QtCore.SLOT("contextMenuAction(str)"), fileName)
self.connect(action, QtCore.SIGNAL("triggered()"), self,
QtCore.SLOT("contextMenuAction(object)"), action)


Cheers

Prashant

Python 2.5.2
PyQt-Py2.5-gpl-4.4.3-1
Win XP, 32 Bit 
-- 
View this message in context: 
http://www.nabble.com/Signal-this-way-tp25655744p25655744.html
Sent from the PyQt mailing list archive at Nabble.com.

___
PyQt mailing listPyQt@riverbankcomputing.com
http://www.riverbankcomputing.com/mailman/listinfo/pyqt