PDA

View Full Version : how to use QSplitter class



qt_user
4th August 2010, 11:26
I want to know about using the append function in QSplitter so as to divide the child widgets into given proportions.........What would happen if I do:


VideoPlayer::VideoPlayer() //A QSplitter type class
{
videoDisplayer = new VideoDisplayer(this);
videoPlayerControls = new VideoPlayerControls(this);

setOrientation(Qt::Vertical);
playerSizeList.append(350);
playerSizeList.append(100);
setSizes(playerSizeList);
}
Does this divide the space taken by videoDisplayer and videoPlayerControls in the ratio 350:100??? or smthing similar??

Lykurg
4th August 2010, 11:34
to realize a ration between two widgets better use QSplitter::setStretchFactor().

qt_user
4th August 2010, 11:53
to realize a ration between two widgets better use QSplitter::setStretchFactor().

Please be more elaborate.............. I want to add that I do not want to "insert stretch".......... I want to divide two sub Widgets over a widget in a given proportion............say for example I have a "parent" widget and its two child widgets namely "Left" and "Right".............. So I want to divide the space occupied by Parent to Left and Right in the ratio 3:1.......Did u get me in the first go itself??

Lykurg
4th August 2010, 13:11
If you always want a fix ratio you have to fetch the resize event and set the sizes yourself. Otherwise put the widgets in the right ratio to the splitter, then ensure with QSplitter::setStretchFactor() that new space will be divided in your wanted ratio.

qt_user
4th August 2010, 13:41
If you always want a fix ratio you have to fetch the resize event and set the sizes yourself. Otherwise put the widgets in the right ratio to the splitter, then ensure with QSplitter::setStretchFactor() that new space will be divided in your wanted ratio.

Thanx a ton...................but could u elaborate the syntax :
void QSplitter::setStretchFactor ( int index, int stretch )
Plz could you elaborate with an example
here how to use "index" and how much to kep the "stretch" for a 3:1 ratio?

ChrisW67
4th August 2010, 23:39
Read "Stretch Factor" under "Layout Management" in Qt Assistant.

Assuming a splitter with two widgets (0, 1):


splitter->setStretchFactor(0, 3); // widget gets 3 out of 4 width/height units
splitter->setStretchFactor(1, 1); // widget gets 1 out of 4 width/height units

Neither widget will shrink below its minimum size though.

qt_user
5th August 2010, 10:36
thanx a ton........