Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt: mutually exclusive checkable menu items?

Tags:

qt

menu

Many Windows programs have mutually exclusive checkable menu items. Qt Designer allows to make each individual item checkable or non-checkable. But is there a way to group a bunch of items and make them mutually exclusive?

like image 467
Violet Giraffe Avatar asked May 02 '14 13:05

Violet Giraffe


1 Answers

Qt just got what you need, you can use QActionGroup class.

Every action in the group will be automatically mutually exclusive.

#include <QActionGroup>

alignmentGroup = new QActionGroup(this);
alignmentGroup->addAction(leftAlignAct);
alignmentGroup->addAction(rightAlignAct);
alignmentGroup->addAction(justifyAct);
alignmentGroup->addAction(centerAct);
leftAlignAct->setChecked(true);

(picture from Qt official site)

enter image description here

like image 118
Tay2510 Avatar answered Oct 21 '22 21:10

Tay2510