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. [solved] Forbid user to uncheck all QRadioButtons when there is only one button.

[solved] Forbid user to uncheck all QRadioButtons when there is only one button.

Scheduled Pinned Locked Moved General and Desktop
8 Posts 3 Posters 5.6k 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.
  • J Offline
    J Offline
    JulienMaille
    wrote on last edited by
    #1

    Not sure the titles is clear enough.
    I insert a random number of QRadioButtons in a layout and would like to have one and only one checked.
    It is the standard behavior of QRadioButtons (thanks to the autoExclusive property) except when there is only one button.
    In that case it is possible to uncheck the button.
    Is this a bug or a feature? How do I get around this?

    1 Reply Last reply
    0
    • K Offline
      K Offline
      koahnig
      wrote on last edited by
      #2

      Maybe "there":http://doc.qt.nokia.com/4.7/qgroupbox.html is some help.

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

      1 Reply Last reply
      0
      • J Offline
        J Offline
        JulienMaille
        wrote on last edited by
        #3

        I already have the manual, thanks. What do you suggest?

        1 Reply Last reply
        0
        • K Offline
          K Offline
          koahnig
          wrote on last edited by
          #4

          This is a link to "QGroupBox":http://doc.qt.nokia.com/4.7/qgroupbox.html . It was not just a link to the manual.

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

          1 Reply Last reply
          0
          • K Offline
            K Offline
            koahnig
            wrote on last edited by
            #5

            OK, by rereading your post I think I got your point.
            However, with QGroupBox you could watch the "clicked()":http://doc.qt.nokia.com/4.7/qgroupbox.html#clicked signal. If there is only one radio button, then you have to set it again, if unset.

            However, I guess you do not have the problem only with one radio button. What is happening, if uncheck the only button of several buttons checked?

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

            1 Reply Last reply
            0
            • J Offline
              J Offline
              JulienMaille
              wrote on last edited by
              #6

              Please stop linking to the documentation randomly.
              It works fine with multiple buttons (you can't uncheck a button), problem appears only with a single button.

              1 Reply Last reply
              0
              • G Offline
                G Offline
                goetz
                wrote on last edited by
                #7

                You can make the radio button uncheckable with a [[Doc:QButtonGroup]]:

                @
                QButtonGroup *bg = new QButtonGroup(this);
                bg->addButton(ui->radioButton);
                ui->radioButton->setChecked(true);
                @

                http://www.catb.org/~esr/faqs/smart-questions.html

                1 Reply Last reply
                0
                • J Offline
                  J Offline
                  JulienMaille
                  wrote on last edited by
                  #8

                  Thanks Volker. It works!
                  I find it weird that the autoExclusive property mimic the behavior of buttons in a group, except when there is only one radio button.

                  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