Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Using splitter with stretch factor
Forum Updated to NodeBB v4.3 + New Features

Using splitter with stretch factor

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 4.0k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    malazbw
    wrote on 23 Feb 2015, 13:38 last edited by
    #1

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

    @split1->setOrientation(Qt::Horizontal);
    split1->addWidget(editor1);
    split1->addWidget(split2);

    split2->setOrientation(Qt::Vertical);
    split2->addWidget(split3);
    split2->addWidget(editor2);

    split3->setOrientation(Qt::Horizontal);
    split3->addWidget(editor3);
    split3->addWidget(editor4);

    split1->setStretchFactor(0,1);
    split1->setStretchFactor(1,1);
    split1->show();@

    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)

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on 23 Feb 2015, 16:28 last edited by
      #2

      Hi, welcome to devnet

      The key here is this quote from the "setStretchFactor":http://doc.qt.io/qt-5/qsplitter.html#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.

      1 Reply Last reply
      0
      • M Offline
        M Offline
        malazbw
        wrote on 23 Feb 2015, 16:41 last edited by
        #3

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

        1 Reply Last reply
        0

        1/3

        23 Feb 2015, 13:38

        • Login

        • Login or register to search.
        1 out of 3
        • First post
          1/3
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved