Toggle text for context menu.
Hi All,
I need toggle text for context menu action.E.g , If i've tow action for context menu , "Open", "Close". If i right click it should show Open and if i choose Open and second time if i right click toggle action Close should display.
Can any body guide me, how to achive this.?
Thank u all.
Re: Toggle text for context menu.
Set the text in the slot for QAction::trigerred signal.
something like -
Code:
void someClass::someSlot()
{
action->setText( action->text() == "Open" ? "Close" : "Open" );
}
Re: Toggle text for context menu.
Quote:
Originally Posted by
aamer4yu
Set the text in the slot for QAction::trigerred signal.
something like -
Code:
void someClass::someSlot()
{
action->setText( action->text() == "Open" ? "Close" : "Open" );
}
Hi Aamer,
Thanks for replying to this message. Actually I need to implement toggle action for context menu. But only one text can be added to QAction, like QAction( _icon, _text, _parent ). In my case i need both "Open" and "Close" for the same action. But it should be toggled. Can u tell me how to implement.
Re: Toggle text for context menu.
How are you showing the context menu ? You must be adding some actions to it somewhere ?
Re: Toggle text for context menu.
Quote:
Originally Posted by
aamer4yu
How are you showing the context menu ? You must be adding some actions to it somewhere ?
I'm creating like following
Code:
Action
::Action( enum ,
const QIcon & icon,
const QString & text,
{
}
Action class is derived from
QAction.
creation of menu action for contextmenu device
--------
createMethode()
{
menu
->addAction
( new Action
( enum value,
QIcon(), tr
( "Open" ), menu
) );
}
Re: Toggle text for context menu.
Is there a reason to inherit QAction ??
What I want to know is how you are showing menu. You need to simply follow the following steps -
Code:
connect(action,trigerred(bool), someClass, mySlot(bool) );
// Add action to any menu u want... when that action is triggered you will reach mySlot function.
// Before I gave hint what to do in mySlot.
Hope you can now join the pieces together :)
Re: Toggle text for context menu.
or you can just create 2 actions one for open and other for close. Store a flag somewhere which according to the current state of your application and just before you show your menu , hide the appropriate action.