The best way to make QToolBar "tested" QToolButtons, where only one of the buttons can be checked at a time?

I want to make a QToolBar with several actions in it, each of which is "checked" (that is, I call setCheckable (true) for each action after it is created, which leaves the button in the down state after clicking).

The only way I can think of β€œunchecking” with other buttons is to connect the signal of each button to the button and uncheck the other buttons when this button is checked.

Is there a better way?

+6
c ++ qt qt4 qtoolbar
source share
1 answer

Create a QActionGroup and let it be the parent of your actions. This QActionGroup will support the state of its children.

 QActionGroup *anActionGroup = new QActionGroup(yourParentWidget); QAction* action1 = new QAction("Action 1", anActionGroup); QAction* action2 = new QAction("Action 2", anActionGroup); QAction* actionN = new QAction("Action N", anActionGroup); action1->setCheckable(true); action2->setCheckable(true); actionN->setCheckable(true); // Add these action to the tool bar 
+11
source share

All Articles