[SOLVED] QLayout items not expanding on resize...



  • I am using the QtCreator with a .ui with the predefined QMainWindow template (Qt Gui Application). I have 1 QHBoxLayout and in the QHBoxLayout is a QTabWidget.

    The tab widget expands to the size of the QHBoxLayout as expected, but wheen I run the application, when I expand the window, the tab widget remains 1 the same size...(the hbox is not expanding on resize)

    I have the tab widgets size policy set to expanding. I have read the docs on the layout management, but was unable to make it expand...

    Any help would be great!



  • Hi there,
    try this:
    when viewing your .ui file in qt creator, right click on the MainWindow ,select layout, another menu appear... choose between vertically,horizontally.....

    The thing is that your mainwindow doesnt have a layout as default,so the widgets inside it wont resize when the windowresize signal is emitted.... you must set it into any of the options I mentioned and hopefully your qhboxlayout will resize automatically.
    Let me know if it worked...



  • When I try to choose layout, all of the layout items are disabled except for Adjust Size unfortunately. Maybe I have to create a layout in my main program loop and then insert the main window into that?



  • Hi,
    yep all of layout items are gonna be disabled because at the begining your .ui is empty, no items on it so in order for those option to be enabled, there must be something created before you to use them. You can check this in Qt documentation or try this:
    add any element from the qt creator and drop it to your mainwindow, then right click ->layout -> choose the layout you want.
    Now this is going to work because there is something in the Mainwindow.

    There are several ways to do what your want, maybe you wanna try creating your QHBoxLayout in your cpp, add the tab widget there too and then set your mainwindow layout from there.
    (this->setLayout(QLayout*);



  • Thank you for your help! I got it all figured out. I got the boxes to be enabled and turned my main ui in a hboxlayout by just adding the tab widget and wrapping it around just that single widget. I ended up turning all my inner widgets in the tab widget to do this as well and set the min max sizes, expanding features ect.

    I have never really ventured into the Qt Layout world. Very cool! Thanks again!



  • Works great!

    [quote author="umerlaton" date="1332730304"]Hi there,
    try this:
    when viewing your .ui file in qt creator, right click on the MainWindow ,select layout, another menu appear... choose between vertically,horizontally.....

    The thing is that your mainwindow doesnt have a layout as default,so the widgets inside it wont resize when the windowresize signal is emitted.... you must set it into any of the options I mentioned and hopefully your qhboxlayout will resize automatically.
    Let me know if it worked...
    [/quote]


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.