Important: Please read the Qt Code of Conduct -

Using splitter with stretch factor

  • I want to display 4 Text Boxes vertically and horizontally on a window





    i used setStretchFactor method, i give 1 for the left big text box, and 1 for the second half(3 textboxes in a splitter)

    the problem is the left text box(editor1) took just 1/3 from the window not 1/2 (like take the half of the window)

  • Moderators

    Hi, welcome to devnet

    The key here is this quote from the "setStretchFactor": doc:

    bq. stretch is not the effective stretch factor; the effective stretch factor is calculated by taking the initial size of the widget and multiplying it with stretch.

    So imagine that at the beginning each widget gets a size of X. The left side of split1 has one widget, so it has width X. The right size has two widgets (editor3 and editor4) side by side so it gets total width of 2X. Since you apply 1 as a stretch for both of these it basically changes nothing - left side is still X and right side is 2X.

    If you want to split it 50/50 you need to apply stretch value 2 to the left side so that it also gets width 2X, equalizing the weights on both sides.

  • Exactly,that's what i found it,minutes before :D
    thank you

Log in to reply