如何把qlineedit和qlabel放在同一行?
时间: 2024-04-13 10:30:09 浏览: 200
要将 `QLineEdit` 和 `QLabel` 放在同一行,你可以使用 `QHBoxLayout` 来水平布局这些控件。以下是一个示例代码:
```cpp
#include <QWidget>
#include <QLabel>
#include <QLineEdit>
#include <QHBoxLayout>
QWidget* widget = new QWidget(this);
QHBoxLayout* layout = new QHBoxLayout(widget);
// 宽度标签和文本框
QLabel* label1 = new QLabel("宽度:", this);
QLineEdit* lineEdit1 = new QLineEdit(this);
layout->addWidget(label1);
layout->addWidget(lineEdit1);
setLayout(layout);
```
在上面的示例中,我们创建了一个 `QWidget` 对象作为容器,并使用 `QHBoxLayout` 来设置水平布局。然后,我们创建了一个 `QLabel` 对象和一个 `QLineEdit` 对象,并依次添加到布局中。
这样就可以将 `QLabel` 和 `QLineEdit` 放在同一行。
希望这对你有所帮助!如果还有其他问题,请随时提问。
阅读全文