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. Button not collinear with QGroupBox
QtWS25 Last Chance

Button not collinear with QGroupBox

Scheduled Pinned Locked Moved Unsolved General and Desktop
stackedwidgetqgroupboxqpushbuttonsizepolicy
4 Posts 2 Posters 828 Views
  • 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.
  • T Offline
    T Offline
    TUStudi
    wrote on 21 Oct 2020, 13:59 last edited by TUStudi
    #1

    Hi,

    I have the following GUI, consisting of some groupboxes and buttons. With the help of the radio buttons i can switsch between a small view and a big view, where the right groupbox will be set invisible. When I run the application with the big view, everything seems okay:

    14b81df1-af52-49b4-a031-79f3efd731b3-image.png

    But when I click on "small" radio button, the green button sticks out, although it should end exactly where the large outer GroupBox ends. Instead, the window is stretched a little to the right

    1b2fea24-b219-4254-9f08-46802ab295f2-image.png

    When I remove the green button, everything seems okay (the window is not stretched anymore to the right, so the problems seems to be in the size policy of the green button.

    6ca209b1-ffff-4137-bd58-52160e05dcd3-image.png

    Propertys of the green Button:

    9e1ee129-657e-4552-bbac-62a552302aa5-image.png

    And here is my function to hide/make visible the elements:

    void Gui::hideSecondOption(bool hide)
    {
        if(hide)
        {
            ui->groupBox_secondOption->setVisible(false);
    
            //A delay is necessary because when a user selects the 'Small' radio button again
            //the window will otherwise be larger than originally
            QTimer::singleShot(50, [this] {
                resize(500, 608);
            });
        } else{
            QTimer::singleShot(50, [this] {
                resize(980, 608);
            });
            ui->groupBox_secondOption->setVisible(true);
        }
    }
    
    P 1 Reply Last reply 21 Oct 2020, 15:29
    0
    • T TUStudi
      21 Oct 2020, 13:59

      Hi,

      I have the following GUI, consisting of some groupboxes and buttons. With the help of the radio buttons i can switsch between a small view and a big view, where the right groupbox will be set invisible. When I run the application with the big view, everything seems okay:

      14b81df1-af52-49b4-a031-79f3efd731b3-image.png

      But when I click on "small" radio button, the green button sticks out, although it should end exactly where the large outer GroupBox ends. Instead, the window is stretched a little to the right

      1b2fea24-b219-4254-9f08-46802ab295f2-image.png

      When I remove the green button, everything seems okay (the window is not stretched anymore to the right, so the problems seems to be in the size policy of the green button.

      6ca209b1-ffff-4137-bd58-52160e05dcd3-image.png

      Propertys of the green Button:

      9e1ee129-657e-4552-bbac-62a552302aa5-image.png

      And here is my function to hide/make visible the elements:

      void Gui::hideSecondOption(bool hide)
      {
          if(hide)
          {
              ui->groupBox_secondOption->setVisible(false);
      
              //A delay is necessary because when a user selects the 'Small' radio button again
              //the window will otherwise be larger than originally
              QTimer::singleShot(50, [this] {
                  resize(500, 608);
              });
          } else{
              QTimer::singleShot(50, [this] {
                  resize(980, 608);
              });
              ui->groupBox_secondOption->setVisible(true);
          }
      }
      
      P Offline
      P Offline
      Pl45m4
      wrote on 21 Oct 2020, 15:29 last edited by Pl45m4
      #2

      @TUStudi

      Is there something right to your groupBox in small layout? Show your ui design / layouts please. It seems that there is still some content, when hiding the second page. So the green button will align to this.

      Btw: I still dont see why you need these timers :)
      The same RadioButton can not get activated twice. You only can toggle between single options of a button group.
      But this has probably nothing to do with your layout issue


      If debugging is the process of removing software bugs, then programming must be the process of putting them in.

      ~E. W. Dijkstra

      1 Reply Last reply
      0
      • T Offline
        T Offline
        TUStudi
        wrote on 22 Oct 2020, 10:55 last edited by
        #3

        @Pl45m4 : Hi.That's a good point, maybe the button is aligned to the "QStackedWidget"? My Ui-elements look like this:

        7b405ea8-eb33-4ddc-9e0f-ec0a1d6b5fbc-image.png

        Regarding timers: I had an issue, where the original window size was not retained after reselection, and the timers fixed the issue.

        P 1 Reply Last reply 22 Oct 2020, 12:31
        0
        • T TUStudi
          22 Oct 2020, 10:55

          @Pl45m4 : Hi.That's a good point, maybe the button is aligned to the "QStackedWidget"? My Ui-elements look like this:

          7b405ea8-eb33-4ddc-9e0f-ec0a1d6b5fbc-image.png

          Regarding timers: I had an issue, where the original window size was not retained after reselection, and the timers fixed the issue.

          P Offline
          P Offline
          Pl45m4
          wrote on 22 Oct 2020, 12:31 last edited by Pl45m4
          #4

          @TUStudi

          Try a cascading horizontal + vertical layout for your page. Could be an issue with the stretch of the last column, where your green button lives or the QGridLayout in general.

          Edit:
          Yeah, that's probably it.
          Gridlayouts can have "empty" cells... Your two groupBoxes with your options take two cells above the button, which takes one, but expands to full size. As soon as you hide the content (grpBox 2nd opt) of second column, the gridLayout only has three rows (grpBx radio, grpBx first, green btn), but the QGridLayout won't delete its second column, but will leave it just empty and this takes some (little) space. Probably exact that amount of space, the green button expands to the right (aligning to the outter border of your grid).

          So try horizontal + vertical layouts or check, if there really is some empty cell (which should be, since you don't take the widget but just hide it).

          QGridLayout::columnCount() should return (at least) 2 when your app is in "small" mode (and also 2 or 3 when you switch to "big")


          If debugging is the process of removing software bugs, then programming must be the process of putting them in.

          ~E. W. Dijkstra

          1 Reply Last reply
          0

          1/4

          21 Oct 2020, 13:59

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved