문제

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?

도움이 되었습니까?

해결책

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top