Reputation: 129
I have some difficulty settings in a game. Because only one option should be active at once i did e.g. for option 'Easy'
//Uncheck all other difficulty options
if(ui->actionMedium->isChecked())
{
ui->actionMedium->setChecked(false);
}
if(ui->actionHard->isChecked())
{
ui->actionHard->setChecked(false);
}
Now the problem is that if i click on an already checked checkbox the checkbox will uncheck. Ok, thats the normal behaviour of a checkbox, so i added
//check if its alreay checked
if(ui->actionEasy->isChecked())
{
ui->actionEasy->setChecked(true);
}
but this doent work and i dont understand why.
As alternativ i could group radiobuttons, but i would like to unterstand why my code doent work.
Upvotes: 0
Views: 1057
Reputation: 29431
You should take a look here it will teach you how to group items and make just one checkable at the same time
Upvotes: 1
Reputation: 8061
If you uncheck the checkbox actionEasy ui->actionEasy->isChecked() == false
and so your code doesn't check this checkbox.
Upvotes: 1