QMenu中Checkbox的实现

QActionGroup* action_group = new QActionGroup( this );

ui->action1->setCheckable(true);

ui->action2->setCheckable(true);

ui->action3->setCheckable(true);

ui->action1->setActionGroup(action_group);

ui->action2->setActionGroup(action_group);

ui->action3->setActionGroup(action_group);

 

QActionGroup is exculsive default. if you want they are checkbox, you must call setExculsive(false).

 

or you can first create the QActionGroup object, then call addAtion(QAction * ) to add actions into group.

 

that's all.

你可能感兴趣的:(QT)