qwidget - Qt widgets not placed correctly -
i've subclassed qwidget , defined constructor way:
loupingwidget::loupingwidget(qwidget *parent): qwidget(parent) { qgroupbox *topgroupbox = new qgroupbox(this); qgraphicsview *xrgbplot = new qgraphicsview(this); qgraphicsview *yrgbplot = new qgraphicsview(this); qgraphicsview *loupe = new qgraphicsview(this); qslider *slider = new qslider(this); qgridlayout *boxglayout = new qgridlayout; boxglayout->addwidget(xrgbplot, 0, 0); boxglayout->addwidget(slider, 0, 1); boxglayout->addwidget(loupe, 1, 0); boxglayout->addwidget(yrgbplot, 1, 1); topgroupbox->setlayout(boxglayout); }
next, trying add in qdialog:
window::window(qwidget *parent): qdialog(parent) { loupingwidget *firstloupindwidget = new loupingwidget(this); loupingwidget *secondloupindwidget = new loupingwidget(this); // qgraphicsview *mainpicture = new qgraphicsview(this); qgridlayout *gridlayout = new qgridlayout; // gridlayout->addwidget(mainpicture, 0, 0); gridlayout->addwidget(firstloupindwidget, 1, 0); gridlayout->addwidget(secondloupindwidget, 1, 1); setlayout(gridlayout); }
when 2 lines commented out, 2 widgets placed horizontally. , that's good, when uncomment lines qgraphicsviews, fills entire window.
what doing wrong?
loupingwidget
doesn't have layout, when it's added layout, layout can't resize according contents. need create layout (e.g. qgridlayout
) in loupingwidget
constructor, add topgroupbox
layout , set layout loupingwidget
's layout.
Comments
Post a Comment