Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to arrange the items in QGridLayout as shown?

Tags:

------------  ------ |          |  | 2  | |          |  |    | |     1    |  ------ |          |  ------   |          |  |  3 | ------------  ------ 

How to arrange the QGridLayout like above?

I tried:

QGridLayout *layout = new QGridLayout(); centralWidget->setLayout (layout);  layout->addWidget (objOne, 0, 0); layout->addWidget (objTwo, 0, 1); layout->addWidget (objThree, 1, 1); 

but failed.

like image 210
Aquarius_Girl Avatar asked Mar 02 '12 11:03

Aquarius_Girl


People also ask

What is grid layout in Qt?

Grid Layout provides a way of dynamically arranging items in a grid. If the GridLayout is resized, all items in the layout will be rearranged. It is similar to the widget-based QGridLayout. All children of the GridLayout element will belong to the layout.

How are widgets added to a grid layout?

The normal way to add a layout is by calling addLayout() on the parent layout. Once you have added your layout you can start putting widgets and other layouts into the cells of your grid layout using addWidget(), addItem(), and addLayout().


1 Answers

Check the addWidget documentation. You can provide the rowSpan and columnSpan

QGridLayout *layout = new QGridLayout(); centralWidget->setLayout (layout);  layout->addWidget (objOne, 0, 0, -1, 1); layout->addWidget (objTwo, 0, 1, 1, 1); layout->addWidget (objThree, 1, 1, 1, 1); 

Notice however that it is much easier to create the desired layout using QtDesigner. Check this Qt documentation page for more details

like image 97
pnezis Avatar answered Sep 24 '22 08:09

pnezis