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. Exclusive Push Button
Qt 6.11 is out! See what's new in the release blog

Exclusive Push Button

Scheduled Pinned Locked Moved General and Desktop
9 Posts 5 Posters 6.7k 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.
  • C Offline
    C Offline
    Ccmc
    wrote on last edited by
    #1

    I want to toggle between several push buttons such that only one of them can be enabled at any given time - essentially, a set of Radio buttons that appear more like Push buttons. Also, they're located in completely different Group Boxes (although within the same dialog of course).

    I'm slightly tempted to use n*n enable/disable signal-slots, but that does sound both ridiculous and onerous. Is there a different way to implement this? If so, can I also pull it off with Qt Designer?

    Thanks.

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

      Use QPushButton's "autoexclusive":http://qt-project.org/doc/qt-5.0/qtwidgets/qabstractbutton.html#autoExclusive-prop property.

      157

      1 Reply Last reply
      0
      • C Offline
        C Offline
        Ccmc
        wrote on last edited by
        #3

        Thanks, but is there a way to do this for buttons with different parent widgets?

        1 Reply Last reply
        0
        • raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          you can do the same like you would do with QRadioButtons, since "QButtonGroup":http://qt-project.org/doc/qt-4.8/qbuttongroup.html is based on QAbstractButtons.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • C Offline
            C Offline
            Ccmc
            wrote on last edited by
            #5

            I tried using the QPushButton "autoexclusive":http://qt-project.org/doc/qt-5.0/qtwidgets/qabstractbutton.html#autoExclusive-prop property, which worked wonderfully for the buttons within the same parent. This does not appear to apply to the buttons beyond the immediate parent, which is what I am trying to do.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi,

              Did you use raven-worx suggestion ? QButtonGroup sounds like what you need.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • N Offline
                N Offline
                NicuPopescu
                wrote on last edited by
                #7

                Hi,

                bq. I’m slightly tempted to use n*n enable/disable signal-slots, but that does sound both ridiculous and onerous. Is there a different way to implement this? If so, can I also pull it off with Qt Designer?

                think simpler :)

                put your push buttons in a list, do just one slot, connect clicked signal of each to the only slot and use

                @QPushButton *button = (QPushButton *)sender();@

                may be focusWidget could be used in some context too, and uncheck all buttons in the list less the sender

                hope this helps :)

                Cheers!

                1 Reply Last reply
                0
                • raven-worxR Offline
                  raven-worxR Offline
                  raven-worx
                  Moderators
                  wrote on last edited by
                  #8

                  [quote author="NicuPopescu" date="1381224884"]
                  think simpler :)

                  put your push buttons in a list, do just one slot, connect clicked signal of each to the only slot and use[/quote]

                  and this should really be simpler than using a simple QButtonGroup?!
                  I would recommend this approach since is more error prone either...

                  --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
                  If you have a question please use the forum so others can benefit from the solution in the future

                  1 Reply Last reply
                  0
                  • N Offline
                    N Offline
                    NicuPopescu
                    wrote on last edited by
                    #9

                    since I quoted him I meant is simpler than his thinking, not others :)

                    bq. I would recommend this approach since is more error prone either…

                    which one is more error prone?

                    myself I found none of them as being error prone once everything is done right ... I reckon though what I suggested is more cumbersome :)

                    Cheers!

                    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