Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How can I implement this layout?



  • Hi,

    I want something that seems fairly simple but I can't manage to find how to do it.

    I need to have widgets A and B in a vertical splitter, with the following constraints:

    • A has a variable height but constrained between 30px and 150px
    • B is expanding in all directions without limit
      I want A to have its minimal (30px) size when the application starts. The user is then free to change it using the splitter.

    I have set A's verticalpolicy to Minimum, and B's vertical policy to Expanding.
    I have set A's minimum height to 30 and maximum height to 150px. (If it matters, I'm doing this through the GUI in QtCreator).
    I have not set any size constraints on B.

    What happens is that A always reaches its maximum (150px) size on application startup.

    Here is how it looks like (A is the QTextEdit at the top, B is the QTableView at the bottom):

    !http://i.imgur.com/AatryYx.png(screenshot from the app)!

    The maximum and minimum allowed sizes of A are well enforced, but I can't figure out how to make A start with its minimum height and not the maximum.

    Any idea?

    Thanks in advance!



  • I think geometry values is what defines the size at startup. You might also want to try 'Preferred' as your size policy instead of minimum.



  • Thanks, but the geometry values are grayed out in QtEditor, I cannot change them!


  • Moderators

    QSplitter is a little tricky control sometimes. What you can do is:

    • reset al the settings you've changed, sizes, policies etc. (just to avoid anything interfering)
    • set only minimum and maximum height for the top widget (don't change policies, they don't really matter here)
    • set Vertical Stretch of the top widget to 1
    • set Vertical Stretch of the bottom widget to something high(like 100)

    This should work as you wanted.
    EDIT: It might not show in the designer, but it will work when you run the app.



  • Thanks, but it is actually worse:

    !http://i.imgur.com/HQjqR2E.png(app screenshot)!


  • Moderators

    You must have set something on a wrong widget. It also looks like a splitter itself is somehow wrongly positioned. Can you show your object tree and describe what you changed on the surrounding widgets?

    By the "top widget" in the previous post I meant textEdit, by the "bottom widget" - tableWidget.
    For reference here's a screenshot with my working example:
    !http://img405.imageshack.us/img405/2364/splitternl.jpg(splitter example)!



  • Ok my bad, I must have set something wrong, I redid it like you said and it is working now. Many thanks!


Log in to reply