Important: Please read the Qt Code of Conduct -

managing radio buttons

  • Hi all -

    I'm writing a program that's using a few radio buttons. The way I'd like this to work, is that the buttons will change not only on user entry, but also from remote updates.

    I'm currently using setDown(), like this:

            switch (p)
            case LEDC_SOLID_OFF:
            case LEDC_SOLID_ON:
            case LEDC_FLASH_SLOW:

    This approach seems to be functional, but it's somewhat unpredictable. I now notice when I push a button from the UI that the former selection is now a blue-filled circle (instead of an empty black circle). Do I need to set the former button as well (using false instead of true)? And if so, am I doing this right, or is there an easier method?

  • Moderators

    @mzimmers said in managing radio buttons:

    Do I need to set the former button as well (using false instead of true)?

    If your buttons are auto-exclusive then it should not be necessary. If you need to tweak that exclusivity, look into QButtonGroup.

    Although to be honest, what you describe (the blue circle) sounds like a Qt bug to me.

  • Moderators

    setDown() is not the correct method to use, but setChecked() is.

    If you want to automatically set all other buttons to false when one turns to true use a QButtonGroup as @sierdzio suggested.

  • Thank you both. I've changed setDown to setChecked, and it does work better. I'm holding off on adding the QButtonGroup, as you pointed out that QRadioButtons are autoexclusive by default.

Log in to reply