Button not collinear with QGroupBox
-
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:
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
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.
Propertys of the green Button:
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); } }
-
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 -
@Pl45m4 : Hi.That's a good point, maybe the button is aligned to the "QStackedWidget"? My Ui-elements look like this:
Regarding timers: I had an issue, where the original window size was not retained after reselection, and the timers fixed the issue.
-
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 theQGridLayout
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 theQGridLayout
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 also2
or3
when you switch to "big")