0

我有一个包含项目操作列表的上下文菜单。默认情况下,菜单中的第一个操作被选中。这是通过使用 QAction 的 setChecked() 和 setCheckable() 属性设置的。But I'm unable to to change the other actions to checked when any other item in the menu is selected. 这是我的代码:

  QAction* action = new QAction(subMenu);

     for(...)
     {
           action = subMenu->addAction(...);
           action->setData(...);
           action->setCheckable(true);
           if(i==1)
           {
             action->setChecked(true);
           }
     }
  connect(subMenu, SIGNAL(triggered(QAction *)),
        this, SLOT(onModeSelected(QAction *)), Qt::UniqueConnection);

void onModeSelected(Qaction* action)
{
    action->setchecked(true);
    ...
}
4

0 回答 0