How to make a Qt Widget grow with the window size?

后端 未结 4 1963
灰色年华
灰色年华 2020-11-29 18:38

I want to have a small QFormLayout that grows to fill its parent widget.

I created a new .ui file using the QWidget template in Qt

相关标签:
4条回答
  • 2020-11-29 18:54

    The accepted answer (its image) is wrong, at least now in QT5. Instead you should assign a layout to the root object/widget (pointing to the aforementioned image, it should be the MainWindow instead of centralWidget). Also note that you must have at least one QObject created beneath it for this to work. Do this and your ui will become responsive to window resizing.

    0 讨论(0)
  • 2020-11-29 19:05

    In Designer, activate the centralWidget and assign a layout, e.g. horizontal or vertical layout. Then your QFormLayout will automatically resize.

    Image of Designer

    Always make sure, that all widgets have a layout! Otherwise, automatic resizing will break with that widget!

    See also

    Controls insist on being too large, and won't resize, in QtDesigner

    0 讨论(0)
  • 2020-11-29 19:12

    I found it was impossible to assign a layout to the centralwidget until I had added at least one child beneath it. Then I could highlight the tiny icon with the red 'disabled' mark and then click on a layout in the Designer toolbar at top.

    0 讨论(0)
  • 2020-11-29 19:15

    You need to change the default layout type of top level QWidget object from Break layout type to other layout types (Vertical Layout, Horizontal Layout, Grid Layout, Form Layout). For example:

    To something like this:

    0 讨论(0)
提交回复
热议问题