[PyQt] Question about QMenu's triggered action
Arnold Krille
arnold at arnoldarts.de
Mon Jun 1 09:59:31 BST 2009
On Sunday 31 May 2009 22:33:51 Tony Willis wrote:
> According to the Qt4 docs, a QMenu is supposed to be capable of emitting a
> `triggered' event which contains the action which was triggered. (I realize
> that its a better coding practice to connect the `triggered' event
> associated with individual QActions to their own separate callbacks, but
> I'm porting an application from Qt3 to Qt4 and I'd prefer not to
> have to write a whole bunch (~50) of new callbacks.) So I'd like to get the
> more global QMenu triggered event to work. Unfortunately, with PyQt, I
> can't seem to see or catch the QMenu's triggered event. The attached PyQt
> demo script illustrates the problem. Can someone point out what I'm doing
> wrong?
I believe you have to decorate the python slot so the connect knows which
arguments it has. Something like @pyqtdecorator( "QAction" )...
And I really don't think its good coding practice to have one connection and
do the split yourself. Cause actually the signals are send individually, then
combined by qmenu, send as one and decomposed into a big select-statement by
you again.
Why not just connect the individual signals?
And connecting to the actions directly has another advantage: Plug them into a
toolbar (additionally to your menu) and you get the same signal (because its
the same action). Or use them in multiple menus (like in the menubar and in
the context menu) and still deal with only one signal. And deal with only one
action to activate/deactivate if needed...
Arnold
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part.
Url : http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20090601/43d02245/attachment.bin
More information about the PyQt
mailing list