You can use a class to implement a simple layout.
# Include <qapplication. h> # include <qmainwindow. h> # include <qpushbutton. h> # include <qslider. h> # include <qvboxlayout> # include <qhboxlayout> # include <qwidget. h ># include <qlcdnumber> class mywidget: Public qwidget {public: mywidget (qwidget * parent = 0, const char * name = 0) ;}; mywidget :: mywidget (qwidget * parent, const char * Name): qwidget (parent) {// create a slider for a single LCD and associate qlcdnumber * LCD = new qlcdnumber (2 ); qslider * slider = new qslider (QT: horizontal, this); slider-> setrange (0, 99); slider-> setvalue (0 ); // use the signal/slot mechanism to connect the valuechanged () signal of the slider with the display () slot of the LCD number connect (slider, signal (valuechanged (INT), LCD, slot (Display (INT); qvboxlayout * layout = new qvboxlayout; Layout-> addwidget (LCD); Layout-> addwidget (slider); setlayout (layout );} class mywidget1: Public qwidget {public: mywidget1 (qwidget * parent = 0);}; mywidget1: mywidget1 (qwidget * parent): qwidget (parent) {// horizontal layout, create a row of four mywidget objects qhboxlayout * layout = new qhboxlayout; mywidget * m [4]; for (Int J = 0; j <4; j ++) {M [J] = new mywidget;} For (INT I = 0; I <4; I ++) {Layout-> addwidget (M [I]);} setlayout (layout);} class mywidget2: Public qwidget {public: mywidget2 (qwidget * parent = 0);}; mywidget2: mywidget2 (qwidget * parent): qwidget (parent) {// This class is vertical layout. Create a row of qvboxlayout * layout = new qvboxlayout; mywidget1 * m [4]; qpushbutton * bn = new qpushbutton ("quit ", this); qobject: connect (bn, signal (clicked (), qapp, slot (quit (); Layout-> addwidget (BN ); for (Int J = 0; j <4; j ++) {M [J] = new mywidget1;} For (INT I = 0; I <4; I ++) {Layout-> addwidget (M [I]); setlayout (layout) ;}} int main (INT argc, char ** argv) {qapplication A (argc, argv ); // Class Object mywidget2 W; W. show (); Return a.exe C ();}