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] ignore QWidget of making QRadioButton exclusive
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] ignore QWidget of making QRadioButton exclusive

Scheduled Pinned Locked Moved General and Desktop
13 Posts 2 Posters 5.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.
  • M Offline
    M Offline
    mohsen
    wrote on last edited by
    #3

    thanks Andre, it seems i couldn't explain the problem well.
    the previous picture was only a vision for my problem. look, this is our real design

    !http://www.use.com/images/s_3/0bba2df42cc2459e1ea3.jpg!

    there's a group box, two widgets which they hold a layout that contains few objects horizontally. unfortunately it's not possible to use only QHBoxLayout inside the groupbox as the objects (inside red rect) would be moved elsewhere outside the QGroupBox. there's other containers which they don't accept layouts.

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on last edited by
      #4

      Ok, I guess this layout could work (once you fix the alignment on the right hand side, anyway).

      So, does the QButtonGroup work? Note that a QButtonGroup is not the same as a QGroupBox...

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mohsen
        wrote on last edited by
        #5

        look at "Item" and "Service". they are two separated Widgets. they're not only a QRadioButton that could be added into QButtonGroup. the problem is that they are Widgets. widget makes the radio button exclusive.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mohsen
          wrote on last edited by
          #6

          for a better understand
          @
          QWidget *w_first=new QWidget();
          QRadioButton *rb_first= new QRadioButton(w_first);

          QWidget *w_second=new QWidget();
          QRadioButton *rb_second= new QRadioButton(w_second);
          

          @

          w_first and w_second added into group box

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #7

            Sorry, but you completely lost me. I understand that the radio buttons have different parent widgets. So what?

            Why do you insist on trying to make the whole widget exclusive, instead of just the radio buttons? That doesn't make any sense. Did you actually look at the documentation of QButtonGroup?

            Note that you can achieve the layout that you have with a simple Grid layout too. It would make it easier to keep the radio buttons and lock icons vertically aligned as well.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              mohsen
              wrote on last edited by
              #8

              using QButtonGroup or QGroupBox or anything else has no difference. i have other custom container which only accepts Widgets. in the above code w_first and w_second might be placed into that custom container, not just a QGroupBox or QButtonGroup. my objects already laid into a QHBoxLayout but the custom container doesn't accept layouts.

              more complete code
              @
              QWidget *w=new QWidget();
              QHBoxLayout *hbl=new QHBoxLayout(w);

              QLabel *lbl=new QLabel(w);
              QRadioButton *rb= new QRadioButton(w);
              QPushButton *btn=new QPushButton(w);
              
              hbl->addWidget(lbl);
              hbl->addWidget(rb);
              hbl->addWidget(btn);
              
              
              CustomContainer->addWidget(w);
              

              @

              say i have several widgets like above. now i want those QRadioButton(s) to be in relation with each other.

              Edit:
              if i could add a layout into the CustomContainer there wouldn't be a problem at all. the problem is those Widgets.

              Moderator edit: Please don't reply to yourself this quickly. Simply edit your post and add to it instead; Andre

              1 Reply Last reply
              0
              • A Offline
                A Offline
                andre
                wrote on last edited by
                #9

                You completely seem to be missing the point that QButtonGroup is not a widget or a layout. It is a QObject that simply manages the checked state of the buttons (and that includes radio buttons) you add to it. It is completely independent from how or where you put the widgets. For all it cares, the buttons are on different forms completely, and it will still manage the checkstates. So all your text about how the buttons are in widgets or layouts or that a container won't accept layouts is completely irrelevant.

                Again: did you actually read the documentation of QButtonGroup? Or did you stop reading after the first sentence or two?

                It really is as simple as adding:
                @
                QButtonGroup* group = new QButtonGroup(this);
                group->addButton(rb);
                group->addButton(rb-second);
                // etc.
                group->setExclusive(true);
                @

                to the code above.

                1 Reply Last reply
                0
                • M Offline
                  M Offline
                  mohsen
                  wrote on last edited by
                  #10

                  Andre, i already know about QButtonGroup :) but please note i'm not talking about basics or a usual action.
                  so all it seems, there's not possible to set the QWidget not act like an exclusive container. i should add another condition to check if the container is the "Custom" one, so it should add items in another way; else i'll add only the layout into my container (might be a QGroupBox or anything).
                  BTW, thanks for your time.

                  1 Reply Last reply
                  0
                  • M Offline
                    M Offline
                    mohsen
                    wrote on last edited by
                    #11

                    oh wait... i'm now understanding what you say!!! i was misunderstood your expression. wait a minute i'll check your solution. it seems to be what i expect.

                    1 Reply Last reply
                    0
                    • M Offline
                      M Offline
                      mohsen
                      wrote on last edited by
                      #12

                      Andre, you were right. i was completely missed the concept of QButtonGroup due to the high working pressure these days.
                      Thanks a million time.

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        andre
                        wrote on last edited by
                        #13

                        [quote author="Mohsen" date="1349088340"]Andre, you were right. i was completely missed the concept of QButtonGroup due to the high working pressure these days.
                        Thanks a million time.[/quote]

                        Ok, so you did not read and understand the docs. Note that it would have saved you (and me) time if you'd just done that when you were told that the first time around...

                        Anyway, glad you got it working. -Please mark the topic as [Solved].- (You already did that).

                        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