1.建立輸入框
QLineEdit* text = new QLineEdit(this);
text->setGeometry(50,80,200,25);
text->setObjectName(QString("text"));
2.建立按鈕
QSize size = QSize(40, text->height());
QPushButton* btn = new QPushButton(this);
btn->setObjectName(QString("PushButton"));
//設定按鈕文字
btn->setText(QApplication::translate("QtGuiApplication3Class", "\346\265\213\350\257\225", nullptr));
// btn->setGeometry(150, 80, 20, 25);
//設定按鈕Size
btn->setMaximumSize(size);
btn->setMinimumSize(size);
3.建立布局
QHBoxLayout* layout = new QHBoxLayout();
layout->setContentsMargins(0,0,0,0);
layout->addStretch();
//添加按鈕到布局
layout->addWidget(btn);
//設定布局
text->setLayout(layout);
4.運作結果
可以分别對文本框和按鈕添加自己的qss樣式來制定自己需要的樣式