我一直在试图弄清楚小部件的坐标是如何到达的。例如在qt文档中,我想知道这是如何完成的。
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(button5, 2, 1);
window->setLayout(layout);
window->show();
作者如何到达上面的坐标,他/她是否使用笛卡尔平面的知识?
答案 0 :(得分:4)
QGridLayout使用简单的行/列逻辑。行和列号像往常一样从0开始。
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
这是你要问的吗?
答案 1 :(得分:1)
QGridLayout :: addWidget有两种不同的形式。
第一个:
void QGridLayout::addWidget(QWidget * widget, int row, int column)
将给定的窗口小部件添加到行,列的单元格网格中 第二个:
void QGridLayout::addWidget(QWidget * widget, int fromRow, int fromColumn, int rowSpan, int columnSpan)
单元格将从fromRow开始,fromColumn跨越rowSpan行和columnSpan列。
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.
参考:qt doc