qt - QGridLayout, 3 panes, not expanding properly -
i'm trying layout window (all in code) qgridlayout
. can add widgets layout , display in window, can't figure out how resize them properly. here's i'd like
[leftmost][--------center---------][rightmost]
those 3 "panes" of window (all 3 of them lists). left , right ones should of static width , hug respective sides, , center should expand fill width window grows (or shrinks).
some code:
// create subviews, add them grid layout, , set layout window. qtableview *list = new qtableview(0); list->setsizepolicy(qsizepolicy::expanding, qsizepolicy::expanding); qtableview *flashlist = new qtableview(0); flashlist->setsizepolicy(qsizepolicy::expanding, qsizepolicy::expanding); qpushbutton *infobutton = new qpushbutton("info!"); qpushbutton *flashfeedsbutton = new qpushbutton("flashfeeds"); qgridlayout *gridlayout = new qgridlayout; // set minimum widths 3 columns of grid gridlayout->setcolumnminimumwidth(gridcolumnfirst, 300); gridlayout->setcolumnminimumwidth(gridcolumnsecond, 300); gridlayout->setcolumnminimumwidth(gridcolumnthird, 300); // set minimum heights rows of grid int headerfooterheight = 44; gridlayout->setrowminimumheight(gridrowfirst, headerfooterheight); gridlayout->setrowminimumheight(gridrowsecond, 200); gridlayout->setrowminimumheight(gridrowthird, headerfooterheight); // set stretch factors gridlayout->setcolumnstretch(gridcolumnfirst, 1); gridlayout->setcolumnstretch(gridcolumnfirst, 2); gridlayout->setcolumnstretch(gridcolumnthird, 1); gridlayout->addwidget(list, 1, 0, qt::alignleft); gridlayout->addwidget(flashlist, 1, 1, qt::aligncenter); gridlayout->addwidget(infobutton, 0, 3, qt::alignright); gridlayout->addwidget(flashfeedsbutton, 0, 1, qt::alignleft); _mainwindow->setlayout(gridlayout);
(as might able tell, going 9x9 grid, point remains, i'm trying middle row (gridrowsecond
) have stretchy columns).
the rows expand fine. problem seems getting widgets @ each cell expand take containing space. how do this? (also, vertically, list expanding properly, not horizontally).
look @ docs on qgridlayout::addwidget:
the default alignment 0, means widget fills entire cell.
but have following:
gridlayout->addwidget(list, 1, 0, qt::alignleft); gridlayout->addwidget(flashlist, 1, 1, qt::aligncenter); gridlayout->addwidget(infobutton, 0, 3, qt::alignright); gridlayout->addwidget(flashfeedsbutton, 0, 1, qt::alignleft);
thus, you've told grid layout want widget aligned left, center, right, , left of cells, respectively. in case want use default alignment allowing widgets fill cells , follow own respective size policies.
Comments
Post a Comment