Cannot set specified sizes when using layouts/splitters



  • I'm running into a very frustrating issue. I set up my GUI in QtDesigner. Everything is laid out perfectly. I add horizontal and vertical splitters to my GUI and resize to fill my Form. Everything is still laid out perfectly. I hit save, close out, and build my application.

    When I run my application, my GUI does not appear as I set it up in QtDesigner. So I reopen QtDesigner and to my surprise the GUI is not laid out the way I had it.

    What is going on? Is there not a way to set up everything in QtDesigner using splitters? Do I have to resize the splitters programmatically? It would be much preferred to not have to do this programmatically if at all possible.

    Any suggestions?


  • Moderators

    Hi,

    did you use setSizes?



  • I did the following steps:

    1. Add widgets to the form.
    2. Set the geometry position/sizes.
    3. Add horizontal splitter.
    4. Set horizontal splitter geometry position/size.
    5. Add vertical splitter with horizontal splitter and another widget as child.
    6. Set vertical splitter geometry position/size.
    7. Save.

    Note: I can do this programmatically no problem.

    @
    const auto osgWindowPixelWidth = 800;
    const auto osgWindowPixelHeight = 450;

    const auto width = this->m_window.vSplitter->width();
    const auto treeViewPixelWidth = (width - osgWindowPixelWidth) / 2;
    const auto propertyViewPixelWidth = width - osgWindowPixelWidth - treeViewPixelWidth;

    QList<int> widths;
    widths.push_back(treeViewPixelWidth);
    widths.push_back(osgWindowPixelWidth);
    widths.push_back(propertyViewPixelWidth);

    this->m_window.hSplitter->setSizes(widths);

    const auto height = this->m_window.vSplitter->height();
    const auto loggerPixelHeight = height - osgWindowPixelHeight;

    QList<int> heights;
    heights.push_back(osgWindowPixelHeight);
    heights.push_back(loggerPixelHeight);

    this->m_window.vSplitter->setSizes(heights);
    @

    The above code works just fine. The problem is, why can't I do this in QtDesigner? Or why have I been unsuccessful at it? Like I said above, I've got everything positioned and sized just perfectly but when I build/run my app the sizes are incorrect.


  • Moderators

    AFAIK you have to do this using code like you did. The "sizes" property isn't available in designer and i see no other way to do it, sorry.


Log in to reply
 

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