Couple of things:
1) Code you've posted at the beggining is just wrong, you change stretch factor on a copy of the size policy! you have to do it this way:
policy.setHorizontalStretch(stretch);
policy.setVerticalStretch(stretch);
widget->setSizePolicy(policy);
QSizePolicy policy = widget->sizePolicy();
policy.setHorizontalStretch(stretch);
policy.setVerticalStretch(stretch);
widget->setSizePolicy(policy);
To copy to clipboard, switch view to plain text mode
2) stretch factor is probably not entirely what you think, from docs:
void QSplitter::setStretchFactor ( int index, int stretch )
Updates the size policy of the widget at position index to have a stretch factor of stretch.
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 setting factors of 20 and 80 will not result in 20%/80% split.
3) Minimum size of graphics view depends on the scene rectangle. If you don't set any then the view will be always squizes to smallest possible regardless of stretch factor.
scene->setSceneRect( 0, 0, 500, 500 ); // this is what you need
view->setScene( scene );
scene
->addEllipse
( 50,
50,
40,
40,
QPen( Qt
::red ),
QBrush( Qt
::blue ) );
sp->addWidget( list );
sp->addWidget( view );
sp->setStretchFactor( 0, 1 );
sp->setStretchFactor( 1, 2 );
this->setCentralWidget( sp );
QGraphicsScene* scene = new QGraphicsScene( this );
scene->setSceneRect( 0, 0, 500, 500 ); // this is what you need
QGraphicsView* view = new QGraphicsView();
QListWidget* list = new QListWidget();
view->setScene( scene );
scene->addEllipse( 50, 50, 40, 40, QPen( Qt::red ), QBrush( Qt::blue ) );
QSplitter* sp = new QSplitter( this );
sp->addWidget( list );
sp->addWidget( view );
sp->setStretchFactor( 0, 1 );
sp->setStretchFactor( 1, 2 );
this->setCentralWidget( sp );
To copy to clipboard, switch view to plain text mode
Code above creates a spliter with list and view in (more or less) 20%/80% initial split. Changing scene rect will require chaning stretch factor to keep 20/80 ratio.
BTW setSize() doesn't work when it comes to setting initial widgets sizes. Never figured it out why though.
Bookmarks