qt5 - QGridLayout with colspan and rowspan -
i can't create qgridlayout one.
i tried failed
qgridlayout *layout = new qgridlayout; layout->addwidget(mytableview,0,0,1,3); layout->addwidget(b1,1,0,1,1,qt::alignright); layout->addwidget(b2,1,1,1,1,qt::alignright); layout->addwidget(b3,1,2,1,1); mainwindow->setlayout(layout);
you can't using qgridlayout
. bottom area need utilize qhboxlayout
, utilize qhboxlayout::addstretch add together spacing.
here example:
widget.h:
#ifndef widget_h #define widget_h #include <qwidget> class qgridlayout; class qhboxlayout; class qspaceritem; class qpushbutton; class qspaceritem; class qpushbutton; class qpushbutton; class qtableview; class widget : public qwidget { q_object public: explicit widget(qwidget *parent = 0); ~widget(); private: qgridlayout *gridlayout; qhboxlayout *horizontallayout; qspaceritem *horizontalspacerleft; qpushbutton *pushbuttonb1; qspaceritem *horizontalspacerright; qpushbutton *pushbuttonb2; qpushbutton *pushbuttonb3; qtableview *tableview; }; #endif // widget_h
widget.cpp:
#include "widget.h" #include<qgridlayout> #include<qhboxlayout> #include<qspaceritem> #include<qpushbutton> #include<qspaceritem> #include<qpushbutton> #include<qpushbutton> #include<qtableview> widget::widget(qwidget *parent) : qwidget(parent) { gridlayout = new qgridlayout(this); horizontallayout = new qhboxlayout(); horizontallayout->addstretch(3); pushbuttonb1 = new qpushbutton(this); pushbuttonb1->settext("b1"); horizontallayout->addwidget(pushbuttonb1); horizontallayout->addstretch(1); pushbuttonb2 = new qpushbutton(this); pushbuttonb2->settext("b2"); horizontallayout->addwidget(pushbuttonb2); pushbuttonb3 = new qpushbutton(this); pushbuttonb3->settext("b3"); horizontallayout->addwidget(pushbuttonb3); gridlayout->addlayout(horizontallayout, 1, 0, 1, 1); tableview = new qtableview(this); gridlayout->addwidget(tableview, 0, 0, 1, 1); } widget::~widget() { }
main.cpp:
#include "widget.h" #include <qapplication> int main(int argc, char *argv[]) { qapplication a(argc, argv); widget w; w.show(); homecoming a.exec(); }
result:
qt5 qtableview qgridlayout
No comments:
Post a Comment