MyClass::MyClass(QWidget *parent)
: QMainWindow(parent)
{
ui.setupUi(this);
ui.pushButton->setFixedSize(40, 30);
ui.lineEdit->setFixedSize(100, 30);
QHBoxLayout *hLayoutBox = new QHBoxLayout();
hLayoutBox->setContentsMargins(0, 0, 0, 0);
hLayoutBox->setSpacing(0);
hLayoutBox->addStretch(1);
hLayoutBox->addWidget(ui.pushButton);
ui.lineEdit->setLayout(hLayoutBox);
ui.lineEdit->setTextMargins(0, 0, 40,0);
}
效果图: