Way to do radio buttons in Qt 4.4.3 menus

前端 未结 1 1709
北恋
北恋 2021-02-18 15:44

On Linux would like to have a set of menu items which are mutually exclusive and have the currently selected one be designated by a radio button instead of a checkbox.

I

1条回答
  •  时光说笑
    2021-02-18 16:24

    I believe you would want to use QtActionGroup to group those menu items which should be mutually exclusive. It also makes them look like a radio button when rendered. Smth like this:

    QActionGroup* group = new QActionGroup( this );
    
    ui->actionTest1->setCheckable(true);
    ui->actionTest2->setCheckable(true);
    ui->actionTest3->setCheckable(true);
    
    ui->actionTest1->setActionGroup(group);
    ui->actionTest2->setActionGroup(group);
    ui->actionTest3->setActionGroup(group);
    

    3 menu items above should be groped together; more details here : QActionGroup Class Reference

    0 讨论(0)
提交回复
热议问题