Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. when setchecked(0), one of the buttonGroup is always checked(solved)

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

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.3k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    houmingc
    wrote on last edited by houmingc
    #1

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

    K 1 Reply Last reply
    0
    • H houmingc

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

      K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      @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

      Vote the answer(s) that helped you to solve your issue(s)

      H 1 Reply Last reply
      0
      • K koahnig

        @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

        H Offline
        H Offline
        houmingc
        wrote on last edited by houmingc
        #3

        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

        1 Reply Last reply
        0
        • H Offline
          H Offline
          houmingc
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved