Search This Blog

Thursday, June 25, 2009

Qt Auto Resize with Qt Designer

If the Qt designer does not seem to handle the resizing of your widgets when running the application, check the following:
  1. To make a widget auto-sizable by itself, it needs to be placed in the layout.
  2. Call the setLayout(top_most_layout_from_the_designer) at the place where you use the designer's code (the place where you call setupUi())
    e.g. ui->setupUi(this);
*because a Layout object is a container for other widgets,
we re-set the layout using ui's layout.

Now the widgets inside the layout can be auto-resize in the Qt Designer.

Convince yourself that all the GUI work should be taken care of by the Designer, if you are using it. Try not to alter the code generated by the Qt Designer (the ui header file). The generated file will be overwritten next time you make change, and that's inconvenient. Unless you really want to handle the resizing yourself, do not implement the resizeEvent. Your code might break i n the future on different machine with different resolution.


Anonymous said...

I worked!

Anonymous said...

It worked! (sorry)