Widget Placement/Resize on MainWindow Resize



  • So this is my setup. Keep in mind, I created all of my objects and widgets within code.

    My MainWindow contains 6 widgets. A Qwt Plot, 2 button sidebars (widgets contains 4 buttons in a vbox layout), a scroll bar, and a button footer(containing 5 buttons in hbox layout), and a progressbar. Unfortunately, I am still fairly new to Qt so I am unfamiliar with how re-sizing events work or how the widgets can dynamically change in size when the mainwindow size changes.

    What I would like to happen is the Qwt plot to expand horizontally and vertically, the scrollbar and the button footer to expand horizontally and move up and down with respect to the Qwt Plot (so no overlapping happens), and the 2 sidebar widgets to just move horizontally with the edge of the Qwt plot, and the progressbar to expand horizontally and move up and down.

    From online my research, most people say to use the layout manager, and use the Qt Designer set it for me. Because I created the widgets in code, I am not sure if this is an option for me.

    Anyone have an good ideas on how to accomplish this task? I know this code might have to get a little ugly since there is quite a bit of variance between the widgets positioning changes, but anyone who can give me a good start on how to configure at least one widget, and go from there, that would be nice!

    Thanks in advance!



  • You should be able to accomplish all of that using layouts, and you certainly don't have to use Qt Designer to do so. For just the side bars and the Qwt plot, you can get what you describe by adding them to a hbox layout, making sure the Qwt plot gets all the stretch (by passing 1 as the second argument of addWidget()). Not sure I understand exactly where you want the other things, but just using a hierarchy of vbox / hbox layouts inside a vbox / hbox layout should make it possible to do whatever you want.



  • I thank you for your quick reply. Will this involve using the resize events for each box layout? or is there a setting to resize automatically without the event.



  • bq. Will this involve using the resize events for each box layout?

    Nope, just let the layout automatically resize the child widgets.



  • Hi,
    I have proble:
    I would like to use mouse to resize QWidget which have set parent = MainWindow like it have set parent = 0 . How I can do this?


Log in to reply
 

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