Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add check/Uncheck QAction in the context menu?

I have created a context menu in Qt and I need the items in the menu works in a checked/Unchecked manner so that it toggles for every click on the respective item. How to add this feature to the QAction just like shown below? enter image description here

like image 876
indira Avatar asked Nov 22 '12 05:11

indira


1 Answers

Here is the relevant section from the manual.

checkable : bool

This property holds whether the action is a checkable action.

A checkable action is one which has an on/off state. For example, in a word processor, a Bold toolbar button may be either on or off. An action which is not a toggle action is a command action; a command action is simply executed, e.g. file save. By default, this property is false.

In some situations, the state of one toggle action should depend on the state of others. For example, "Left Align", "Center" and "Right Align" toggle actions are mutually exclusive. To achieve exclusive toggling, add the relevant toggle actions to a QActionGroup with the QActionGroup::exclusive property set to true.

Access functions:

bool isCheckable() const

void setCheckable(bool)

Notifier signal:

void changed()
like image 164
Marcus Avatar answered Sep 18 '22 23:09

Marcus