qt QHBoxLayout详解

qt QHBoxLayout详解

insertWidget(int , QWidget *, int , Qt::Alignment ):**在布局的指定位置插入一个子控件。

#include

#include

#include

#include

#include

#include

class MyWidget : public QWidget {

public:

MyWidget() {

QHBoxLayout *layout = new QHBoxLayout(this);

复制代码

QLabel *label = new QLabel("Name:", this);

layout->addWidget(label);

QLineEdit *lineEdit = new QLineEdit(this);

layout->addWidget(lineEdit);

QPushButton *button = new QPushButton("Submit", this);

layout->addWidget(button);

layout->setSpacing(10); // 设置控件间距

layout->setContentsMargins(5, 5, 5, 5); // 设置边距

setLayout(layout);

}

};

int main(int argc, char *argv[]) {

QApplication app(argc, argv);

复制代码

MyWidget widget;

widget.resize(300, 100);

widget.show();

return app.exec();

}

相关推荐

兄弟结婚送什么礼物合适
365bet官网体育娱乐

兄弟结婚送什么礼物合适

🗓️ 07-05 👁️ 1170
一篇文看懂西文字体分类 - 字由
365bet官网体育娱乐

一篇文看懂西文字体分类 - 字由

🗓️ 10-01 👁️ 3939
迪达拉vs佐助多少集了(佐助vs迪达拉哪一集)
日博365哪个是真的

迪达拉vs佐助多少集了(佐助vs迪达拉哪一集)

🗓️ 09-12 👁️ 1107

友情链接