stretching and anchoring of a widget

  • In my centralWidget I want to have a widget that is anchored to the top left and is stretching along with the main window (/centralWidget).

    I can't seem to find how to do that inside the QT Creator design view.
    Do I have to do that programmatically?

    (using QT Creator 3.4.3 with QT 5.5.0 under linux)


  • Hi,

    usually you can do this using layouts.
    Can you post a sketch of what you want achieve??

  • The thing is that in the Qt Creator design view there's no way to set anchors or stretching with the layout, as far as I managed to find.

    Here's an image of what I want to have:

    The green part is the widget, as you can see even when the window get bigger the widget still fills the width of the parent.

    I hope that makes it clear.

  • The green widget should be set to preferred (expand width) and fixed (fixed height) with minimum/maximum values.

    Have you tried

    // after ui setup

    on your centralWidget's Layout? More on flags, here.

    I hope that helps

  • The problem is that the green widget isn't resizing when the window is and so its width stays fixed, even though the sizePolicy for it is:

    • horizontal policy: preferred
    • vertical policy: fixed
    • horizontal stretch: 1
    • vertical stretch: 0

    I haven't used the Qt::AlignTop as the widget stays aligned to top as it is, that's not an issue, only the width is the problem.
    I just want it to fill the parent.


  • Hi,

    I suggest to use Expanding as Horizontal Policy

  • @mcosta that seems to have no effect on things.
    the same result as before.

Log in to reply

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