Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QButtonGroup at least one button must be checked.
Qt 6.12 LTS is out! See what's new in the release blog

QButtonGroup at least one button must be checked.

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 1.5k Views 1 Watching
  • 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.
  • G Offline
    G Offline
    gozag
    wrote on last edited by
    #1

    I have a QButtonGroup of QCheckboxes and I want to ban unchecking all QCheckBoxes. At least one must always be checked.

    jsulmJ 1 Reply Last reply
    0
    • G gozag

      I have a QButtonGroup of QCheckboxes and I want to ban unchecking all QCheckBoxes. At least one must always be checked.

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @gozag https://doc.qt.io/qt-6/qbuttongroup.html#exclusive-prop

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      G 1 Reply Last reply
      1
      • jsulmJ jsulm

        @gozag https://doc.qt.io/qt-6/qbuttongroup.html#exclusive-prop

        G Offline
        G Offline
        gozag
        wrote on last edited by
        #3

        @jsulm I am saying that at least one must be checked. Not saying that only one can be checked.

        Well what I did is:

        • check when all are checked off
        • when it is remove the button from the group to prevent it from triggering the signals
        • check the button
        • add it back to the group

        Is there no other way?

        jsulmJ 1 Reply Last reply
        0
        • G gozag

          @jsulm I am saying that at least one must be checked. Not saying that only one can be checked.

          Well what I did is:

          • check when all are checked off
          • when it is remove the button from the group to prevent it from triggering the signals
          • check the button
          • add it back to the group

          Is there no other way?

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @gozag You can connect a slot to https://doc.qt.io/qt-6/qbuttongroup.html#buttonToggled In that slot if "checked" is false check all other buttons. If all other buttons are also not checked then check the button (https://doc.qt.io/qt-6/qabstractbutton.html#checked-prop).

          Not sure there is an easier way.

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          JoeCFDJ 1 Reply Last reply
          1
          • jsulmJ jsulm

            @gozag You can connect a slot to https://doc.qt.io/qt-6/qbuttongroup.html#buttonToggled In that slot if "checked" is false check all other buttons. If all other buttons are also not checked then check the button (https://doc.qt.io/qt-6/qabstractbutton.html#checked-prop).

            Not sure there is an easier way.

            JoeCFDJ Offline
            JoeCFDJ Offline
            JoeCFD
            wrote on last edited by
            #5

            @jsulm I would define a std::bitset to do it for all checkboxes. If its value is 0, check the default one,

            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
            • Unsolved