Setting the particular item in a menu as checked when the action is triggered

2.3k views Asked by At

I have a context menu with a list of item actions. By default the first action in the menu is selected. This is set by using the setChecked() & setCheckable() properties of QAction. But I'm unable to to change the other actions to checked when any other item in the menu is selected. Here is my code:

  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);
    ...
}
0

There are 0 answers