qt - Resizing child widget with keeping aspect ratio when parent widget resized -


i have 4 widgets in qwidgets named fourwindowwidget trying put these 4 widgets in fourwindowwidget 1 @ top , remaining under while top 1 should have 70% of size of fourwindowwidget. tried following :

qsize size = ui->fourwindowwidget->size();  ui->view1->setfixedheight(size.height()*0.70);  qhboxlayout * lay = new qhboxlayout(); lay->addwidget(ui->view2); lay->addwidget(ui->view3); lay->addwidget(ui->view4); lay->setmargin(0); lay->setcontentsmargins(0,0,0,0);  qgridlayout * mainlay =  new qgridlayout; mainlay->addwidget(ui->view1,0,0); mainlay->setcontentsmargins(0,0,0,0); mainlay->sethorizontalspacing(0); mainlay->setspacing(0); mainlay->setmargin(0); mainlay->addlayout(lay,1,0);  delete ui->fourwindowwidget->layout(); ui->fourwindowwidget->setlayout(mainlay); this->update(); 

now problem view1 have fixed size size of fourwindowwidget not fixed. changes when remove other widget around closing dock widget. resize expected, or don't want make fixed. when ever fourwindowwidget resized child widgets should per ratio set. unable cause 1. there no signal inform resize height of internal widget calculated. 2. no other way found set 70% height of top widget rather setfixedheight in grid layout.

i have tried setting qsizepolicy sethieghtforwidth iit not working solution. please suggest me way.


the question kind of duplicat of resizing qt widgets based on window size there nobody answered.

setting stretch factor layout should work. i'm not sure why using grid layout this, when adding in same column, here example works:

mainwindow::mainwindow(qwidget *parent) :     qmainwindow(parent),     ui(new ui::mainwindow) {     gridlayout = new qgridlayout;     this->centralwidget()->setlayout(gridlayout);     label1 = new qlabel("l1");     label2 = new qlabel("l2");     label3 = new qlabel("l3");     label4 = new qlabel("l4");     gridlayout->addwidget(label1, 0, 0);     gridlayout->addwidget(label2, 1, 0);     gridlayout->addwidget(label3, 2, 0);     gridlayout->addwidget(label4, 3, 0);     gridlayout->setrowstretch(0,7);     gridlayout->setrowstretch(1,1);     gridlayout->setrowstretch(2,1);     gridlayout->setrowstretch(3,1); } 

in example label1 take 70% of available vertical space, while other labels take combined 30% of available vertical space.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

debian - 500 Error upon login into Plesk Admin - auth.php3? -