qt - QGridLayout 坐标系

标签 qt qt4

我一直在试图弄清楚小部件的坐标是如何到达的。例如在 qt 文档中,我想知道这是如何完成的。

Buttons example

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();

作者是如何得到上面的坐标的,他/她是否使用了笛卡尔平面的知识?

最佳答案

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

这是你要问的吗?

关于qt - QGridLayout 坐标系,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6856137/

相关文章:

python - 使用修改键在 pyqt4 中拖放

visual-studio - LNK1112 模块机器类型 'X86' 与目标机器类型 'x64' 冲突

python-3.x - VTK 渲染在 PyQt 中无法按预期工作

c++ - QChar 转 wchar_t

c++ - 我如何在 Qt Creator 的主窗口中声明对象?

c++ - Qt 围绕其中心点旋转文本

c++ - 获取两个 QList 之间的交集的 Qt 方法是什么?

c++ - 在 QDateTime 中格式化小时数的 Qt4 问题

qt4 - 将 QTextCursor 移动到末尾的问题

c++ - qt Qmake 为一个项目生成pkgconfig