Qt World Summit: Register Today!

How can I get a child widget to resize its parent ?

  • I have a (seemingly) simple problem that I'm struggling to solve.

    I want to have a (fixed size) image widget and a (variable length, single line) label widget inside a frame widget ... so far, so good.

    But when I change the text of the label widget, I would like the parent frame to resize (up to a maximum) to accommodate the bigger / smaller label widget.

    For the parent "frame" I've tried frame, grid, hbox ... none of which seem to do what I want.

    If I have the label on its own (not as a child widget), it resizes as expected.

    Can anyone tell me how (if at all) this can be achieved ?

    Needless to say, I'm quite new to Qt, so I may be overlooking something trivial :)

    Mark J.

  • @MPFJ
    When you say you've tried stuff with widgets, have you been using layouts (https://doc.qt.io/qt-5/layout.html, QLayouts)? Some people try to use multiple widgets without layouts.

  • @JonB Yes.

    In the form designer, I made a grid layout with label child.

    Resizing the grid layout, resizes the label, no problem.

    But if I programmatically change the label text, the grid doesn't change size, which is the effect I'm after.

    I'm guessing this is by design, so I was wondering if it's possible?

    Mark J

Log in to reply