1

So I'm working on a QT5 based GUI and I have a main window that fills in an empty area depending on user input. The gui looks roughly like this

---------------------  
|Qlabel 1 |Qlabel 2 |  
|-------------------|  
|                |B1|  
|      MAIN      |B2|  
|                |B3|  
|-------------------|  

B1,B2, and B3 are buttons which create popups that ask for user input. Main is the issue. In QT Creator I've set main to be a widget. I've also created a widget which has a layout (again in QT creator) which I'll call filler. On input an instance of filler, I add filler to a layout which I then set on main. The issue I'm having is that sizing seems to be totally dependent on the QT creator sizing of the layout inside of filler.
What I want is for filler to scale to the size of the encapsulating MAIN widget and I'm not sure how to go about this. Any input is helpful!
Edit:
The code which fills in main is roughly

fillerWidget* filler = new fillerWidget(ui->mainWidget, QString::fromStdString(input1), input2);
QGridLayout* fillerLayout = new QGridLayout();
fillerLayout->addWidget(filler, 0, 0);
ui->mainWidget->setLayout(fillerLayout);
ui->mainWidget->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
filler->adjustSize();
Darakian
  • 619
  • 2
  • 9
  • 22
  • Do you get a runtime warning in the line `ui->mainWidget->setLayout(fillerLayout);`? Ususally, you cannot change the layout of a widget once it was set – king_nak Apr 10 '17 at 12:12
  • Nope no runtime warning. I clear out the layout before setting it each time the user input needs changes. – Darakian Apr 10 '17 at 12:16
  • I think there's a problem with the layout of the main part in your sketch. Can you post (a stripped down version) of your .ui file? – king_nak Apr 10 '17 at 12:54
  • 0 0 0 0 18 – Darakian Apr 10 '17 at 13:01
  • I don't have the character count to space that out, but that's mainWidget from mainwindow.ui – Darakian Apr 10 '17 at 13:02
  • Have you tried to set a main layout directly from QT Designer (Right click on main/top level widget, set layout...) ? – Ayak973 Apr 10 '17 at 13:14
  • I so have a main grid (named gridlayout2) layout of which the mainWidget is a member. I'm not sure that helps me though. – Darakian Apr 10 '17 at 13:17
  • And what about change the size policy from preferred to expand? [Layout explanation](http://stackoverflow.com/a/4672493/5847906) – Ayak973 Apr 10 '17 at 13:33
  • I've done that as well (and having no size policy set) all with no change in the results. – Darakian Apr 10 '17 at 13:41
  • The important part of the UI file is where you place mainWidget in the form. Can you edit your question and amend the UI file? – king_nak Apr 11 '17 at 12:20
  • I found my answer here https://stackoverflow.com/questions/15183309/how-to-make-new-widgets-fill-available-space – Darakian Apr 18 '17 at 18:59

0 Answers0