[Qt Creator] Layouts inside a DockWidget



  • Hi,

    Using QT Creator, I'm trying to create a dock widget that has a series of other gadgets inside it (buttons, combo boxes and a tree widget), and have the gadgets auto-expand horizontally as the dock widget is resized.
    I know it can be done in pure C++ code, and I've done the same thing using layouts in other Apps that don't require docks, but I can't get it to work in the designer inside a dock.

    To recreate my problem, just create a fresh App, add a Dock Widget, add some gadgets to the dock, select them and choose 'Layout in a group form'. After doing this I can't seem to find any combination of settings that automatically resize the widgets when the dock is resized.
    Am I just getting the settings wrong (what should they be??) or am I doing this completely wrong?
    It seems like something that should be very easy to do, but I'm having no luck at all.

    Thanks for any help.


  • Lifetime Qt Champion

    IIRC, QDockWidget is just a container, so basically, you set a widget on it, and the other gadgets on that widget.



  • Yes, I didn't mention it, but QT Creator automatically places a QWidget under the QDockWidget, and so everything is placed under that. But I still can't get it to work as I'd like it to.

    I think that the QWidget under QDockWidget needs to BE the QFormLayout, but whenever I create the layout QT Creator automatically creates a new QFormLayout instead.

    i.e. I think it should be this:
    @
    -QDockWidget
    -QFormLayout
    -QPushButton
    -etc
    @

    but when I create the layout QT creator sets it up like this:

    @
    -QDockWidget
    -QWidget
    -QFormLayout
    -QPushButton
    -etc
    @

    I don't know how to persuade Creator to do the former (if the former is indeed correct)


  • Lifetime Qt Champion

    The later is the correct version. Programmatically, you would create the widget (and all what goes inside) then the QDockWidget, and assign the widget to the DockWidget.



  • ok, well there must be something I'm doing wrong elsewhere, as although the form layout works, nothing resizes with the dock widget :(



  • Figured it out.

    In my first post I said
    "add some gadgets to the dock, select them and choose ‘Layout in a group form’. "

    This is wrong, I needed to add the gadgets to the dock, then select the DOCK and choose 'Layout in a group form'.
    Seems obvious now, but was driving me mad earlier.


Log in to reply
 

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