when setchecked(0), one of the buttonGroup is always checked(solved)



  • In the code below, when pushButton43 get clicked, there is always one button checked. i need all the button to be unchecked. What is the problem?

    '''
    QButtonGroup* ButtonGroup = new QButtonGroup(this);
    ButtonGroup->addButton(ui->pushButton11);
    ButtonGroup->addButton(ui->pushButton12);
    ButtonGroup->addButton(ui->pushButton13);
    ButtonGroup->addButton(ui->pushButton14);

    ui->pushButton11->setAutoExclusive(true);
    ui->pushButton12->setAutoExclusive(true);
    ui->pushButton13->setAutoExclusive(true);
    ui->pushButton14->setAutoExclusive(true);
    

    void MainWindow::on_pushButton43_clicked()
    {
    ui->pushButton11->setChecked(0);
    ui->pushButton12->setChecked(0);
    ui->pushButton13->setChecked(0);
    ui->pushButton14->setChecked(0);
    }


  • Moderators

    @houmingc
    Hi and welcome to devnet

    That seems the intended behaviour of a QGroupBox it says in the detailed description:
    An exclusive button group switches off all checkable (toggle) buttons except the one that has been clicked. By default, a button group is exclusive.

    The behaviour stems from the exclusive property



  • Thanks. I want only one of the button able to be selected, but also all button reset or unchecked whenever a reset button is clicked



  • I solved the puzzle by creating another button making it invisible. Thanks


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.