开发者

QGridLayout Co-ordinates System

开发者 https://www.devze.com 2023-03-23 23:57 出处:网络
I have been trying to figure out how the coordinates of a widget is arrived at.For instance in the qt documentation,i wonder how this is done.

I have been trying to figure out how the coordinates of a widget is arrived at.For instance in the qt documentation,i wonder how this is done.

QGridLayout Co-ordinates System

QGridLayout *layout = new QGridLayout;
     layout->addWidget(button1, 0, 0);
     layout->addWidget(button2, 0, 1);
     layout->addWidget(button3, 1, 0, 1, 2);
     layout->addWidget(button4, 2, 0);
     layout->addWidget(b开发者_运维技巧utton5, 2, 1);

     window->setLayout(layout);
     window->show();

How did the author arrive at the coordinates above,did he/she use knowledge from the Cartesian plane ?


QGridLayout uses simple row/column logic. Row and Column numbers start from 0 as usual.

QGridLayout *layout = new QGridLayout;

layout->addWidget(button1, 0, 0); //Add to row 0 column 0
layout->addWidget(button2, 0, 1); //Add to row 0 column 1

layout->addWidget(button3, 1, 0, 1, 2); //Add to row 1 column 0 and span to row 1 column 1


layout->addWidget(button4, 2, 0);//Add to row 2 column 0
layout->addWidget(button5, 2, 1);//Add to row 2 column 1

Is this what you are asking ?


QGridLayout::addWidget has two different forms.
The first:

void QGridLayout::addWidget(QWidget * widget, int row, int column)

Adds the given widget to the cell grid at row, column.
The second one:

void QGridLayout::addWidget(QWidget * widget, int fromRow, int fromColumn, int rowSpan, int columnSpan)

The cell will start at fromRow, fromColumn spanning rowSpan rows and columnSpan columns.

layout->addWidget(button2, 0, 1);//button2 will be added to row 0, column 1
layout->addWidget(button3, 1, 0, 1, 2);//button3 will be added to row 1, column 0 spanning 1 row and 2 columns.

Reference: qt doc

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号