How to correctly apply size changes to complicated layouts/widgets

  • Hi,
    I have a problem to understand the resizing mechanism of a layout.

    First: What do I want to achieve:
    I have 9 widgets that attached to multiple layouts in a hirachel way.
    All widgets are inside a QDockWidget.
    I want that if I resize the QDockWidget the size of some widgets is also changed especially from the TableView.

    At first I thought my problem comes from my complicated layout structure but I could reproduce the same issue with a simple layout.

    Simple setup:
    I have a QTableView and a lineedit widget.
    The two widgets are attached to a simple horizontal layout.

    My first approach was to simply change the size of the TableView and let the layout make the rest.
    @ QRect rec = ui.tableView->geometry();
    Without layout the TableView width is changed but in connection with a layout the size didn't change.

    Next thing I tried was to change the size of the layout and let "expanding" mechanism of the TableView do the rest but this failed also. (Width stays the same)
    @QRect test = ui.verticalLayout->geometry();

    Does anybody have an idea what I am doing wrong or how can I achieve the resizing mechanism in the best manner.


  • Lifetime Qt Champion


    When using layout you generally let it handle resizing for you. What you can do is give hints to the layout as who should take more place (the stretch parameter).

    You can also set the minimum width of your widget if you need it.

    However, can you describe more precisely how you would like your layout to be modified ?

  • I want that the Widgets (that are in a layout) inside a dockwidget automatically adjust where size to the size of the dockwidget.

    So I enlarge the dockwidget horizontally and the tableview (One of the Widgets) enlarges at the same amount of pixels as the dockwidget.

  • Lifetime Qt Champion

    Then you should set the stretch of your QTableView to e.g. 2

  • Hi,
    thanks for the answer but I did what you said and set the stretch of the QTableView to 2 but I cant see any difference in the size behaviour of the QTableView.

    Inside or outside the layout the behavior is still the same.
    Iam not able to bring the QTableView (if it is inisde a layout) to use all the space inside the QDockWindow and to automatically adjust to the window size.

  • Moderators

    try setting it to a higher value... 10, or even 100

    Alternatively you can play around with the "size policies": of the widgets.
    E.g. set the table to 'expanding' and the other widgets to 'fixed' (in the according direction)

  • Sorry I am more and more confused.

    I insert a QTableView inside the QTDesigner.
    I set the horizontal/vertical stretch to 100 and the size policy to "expanding" and this has zero effect on my system.

    As far as I understood your answers the QTableView size should than adjust automatically to the size of window or am I wrong?

  • Moderators

    [quote author="Fenrix" date="1422274203"]
    As far as I understood your answers the QTableView size should than adjust automatically to the size of window or am I wrong?[/quote]
    Size policies are only hints how the widget's size hint is interpreted inside the layout.
    I never used the QtDesigner to compose widgets, but i don't know if there is automatically a layout created.

Log in to reply

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