[Qt-interest] Can a QAction be replaced at runtime ?

Scott Aron Bloom Scott.Bloom at sabgroup.com
Tue May 12 17:50:32 CEST 2009


Depending on the complexity of the replacement, yours is a fine solution…

 

I can give you some other possible solutions..

 

You may also want to have 1 slot, and use QSignalMapper, and you rebuild the menu each time it is about to be shown (using signal QMenu::aboutToShow() )

 

Or, I have been known to change the text of a single QAction based on state..  My slot becomes a bit more complex, but QAction::setText should do

 

I have also done the “swap out” like you are doing…  It is clunkly, but all menu building algorithms  tend to be ;)

Scott

 

From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Stephen Collyer
Sent: Tuesday, May 12, 2009 8:29 AM
To: qtInterest
Subject: [Qt-interest] Can a QAction be replaced at runtime ?

 

I have a QMenu containing a QAction which starts an activity i.e. with text like:

"Start X"

When the activity X is started, I want to toggle the available action to say:

"Stop X"

I've created a start action with text "Start X" and a separate stop action with
text "Stop X". At the moment I'm toggling the actions by inserting the stop action before
the start action, then removing the start action. This works, but feels a little clunky. 

Is it possible to directly replace a QAction in a menu ?

-- 
Stephen Collyer

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090512/44b71cb3/attachment.html 


More information about the Qt-interest-old mailing list