Set start size of layout in splitter



  • Hey,
    I am sure, this is just a basic oparation, but playing with the settings and looking to questions didn't help me.
    I want to set the start size of a layout, that is with other layouts in a splitter. But I want to be able to resize it when the program is running (like I normally do with splitters just dragging the corner).
    How can I do this?
    Thanks for answers!


  • Qt Champions 2016

    Hi
    The size is determined by the widgets.
    http://doc.qt.io/qt-5/qsplitter.html#details

    "The initial distribution of size between the widgets is determined by multiplying the initial size with the stretch factor. "

    So setting min/max size will alter (on the widgets) where the middle is.

    So as far as i know, you cannot just set the (drag) handle to a position.



  • @mrjj
    I'm sorry, I don't get it...
    The strech factor is 0. Setting it to another does not make a difference.
    I want all the widgets in the layout resizeable by dragging the handle in the window.
    And I have a range min to max of the layout. But the layout always starts with the max possible width. Every time I have to resize is, that it is not so big anymore. I want this to happen automatically...


  • Qt Champions 2016

    Ok. Its short, the handle is not just a position. its based on the widgets inserted.
    The doc explains it in details :)

    you can use
    ui->splitter->setSizes(QList<int>() << 200 << 100);
    or set the stretch factor on the widgets
    leftWidget->sizePolicy().setHorizontalStretch(1);
    rightWidget->sizePolicy().setHorizontalStretch(2);



  • @mrjj
    I have a vertical layout (no left or right widgets, sorry forgot to mention that). Setting a strech factor to every widget there would take too much time and the number of widgets that are inside the layout can vary (and I still don't get this strech thing).
    I will read the docs, I don't understand the concept behind the resizing of layouts. I can resize them and nothing happens (what kind of resizing is this...), I will maybe by reading the docs.
    I will update here when I am finished. Thanks for your help anyway!


  • Qt Champions 2016

    Hi
    should also work on a vertical splitter
    The stretch thing also made me wonder in the beginning but its just a measure for how much each side get
    so if you say 2,1 the first get twice as much .
    Just play with it and it will be clear.

    Im not sure what u mean when you say resizing of layouts.
    They will adjust any widgets inside them. Based on each widget settings.
    The layout itself only have margins and other properties.
    All resize is based on the widgets.

    • I can resize them and nothing happens
      Well then its most likely not setup correctly. :)


  • @mrjj
    But I can not set the horizontal stretch of a layout in a splitter.
    I am trying to set the width of a layout that is next to other layouts in a horizontal spliter.
    The splitter splits multiple layouts. But in the code, I can not call

    ui->horizontal_layout_1->setHorizontalStretch(2);
    

  • Qt Champions 2016

    @Niagarer said in Set start size of layout in splitter:

    ui->horizontal_layout_1

    This that one of the free floating layouts ?
    alt text


Log in to reply
 

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