[Interest] Uncheck Button in QML ButtonGroup

Bullinger, Julius julius.bullinger at intel.com
Wed Aug 16 13:46:13 CEST 2017


Hi,

given the ButtonGroup example<https://doc.qt.io/qt-5/qml-qtquick-controls2-buttongroup.html> from the documentation:

  ButtonGroup { id: group }

  RadioButton {
      checked: true
      text: qsTr("Option A")
      ButtonGroup.group: group
  }

  RadioButton {
      text: qsTr("Option B")
      ButtonGroup.group: group
  }

When the application is started, all buttons are unchecked (group.checkedButton  is null). As soon as a button is clicked, the checkedButton is set, and selection can only be changed between buttons.

Is there any way to uncheck a button, when it's clicked in a checked state? It's supposed to work by setting group.checkedButton  to null again, but this doesn't work when doing it on a Button signal. I tried several approaches like these:

  Connections {
    target: buttonGroup.checkedButton
    onClicked: if(buttonGroup.checkedButton.checked) {
      buttonGroup.checkedButton.toggle()
      // or setting checked to true,
      // or moving the connection to each Button,
     // or using onPressed/onReleased,
     // or setting group.checkedButton to null
     // doesn't work either
    }
  }

But for all of these, the button is toggled checked > unchecked > checked immediately when it's clicked.

It does work when omitting the ButtonGroup, but I need mutually-exclusive selection.

Thanks and best regards,
Julius
Intel Deutschland GmbH
Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
Tel: +49 89 99 8853-0, www.intel.de
Managing Directors: Christin Eisenschmid, Christian Lamprechter
Chairperson of the Supervisory Board: Nicole Lau
Registered Office: Munich
Commercial Register: Amtsgericht Muenchen HRB 186928
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20170816/695b1a04/attachment.html>


More information about the Interest mailing list