PDA

View Full Version : How to make QSplitter to split my widgets in right proportions?



code_err
5th January 2012, 23:21
I have some troubles with QSplitter Widget. I have quite advanced nested layouts but everything works except this one.
I'll try to picture how this part of my layout looks like.

QVBoxLayout
- QSplitter
- QTabWidget (with 2 tabs)
- Widget derived from QTextEdit
- QLabel

The problem is that my QTextEdit Widget should behave in a way i set in its constructor(i.e.):
{
setMinimumHeight(120);
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
}
and for QTabWidget i set
setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);

but when i run my app QTextEdit takes most of the window splitted by these two.

Tried to put first code (that in {}) to its parent constructor but nothing changes
I probably don't understand yet fully QSizePolicy and things related...

I want QTextEdit to has its minimal height all the time but in a opportunity to change it manually by handler and rest of the window should be given to QTabWidget.
Could anyone help, give me some hints?

ChrisW67
5th January 2012, 23:28
From the docs (emphasis is mine):
QSizePolicy::Minimum: The sizeHint() is minimal, and sufficient. The widget can be expanded, but there is no advantage to it being larger (e.g. the horizontal direction of a push button). It cannot be smaller than the size provided by sizeHint().
Try QSizePolicy::Fixed... not that I can see a point to a splitter that cannot be moved.

code_err
6th January 2012, 00:19
Yes but i just thought that the second widget with Expanding policy predominates this one's policy.
Will try with Fixed.

Spitfire
9th January 2012, 10:36
Can you post some actual code how you create the layout?
Do you set stretch on any of the items when adding them to the layout?

Setting anything like minimum, preffered or fixed should work fine.

Zlatomir
10th January 2012, 13:13
If you want one widget to expand more than another use the H/V Stretch... QSizePolicy::setHorizontalStretch (http://developer.qt.nokia.com/doc/qt-4.8/qsizepolicy.html#setHorizontalStretch), look for vertical in the same page and use the one you need in your project to set widget "space" as you like.