简述
首先我们来看一下想要实现的图
有时候我们的确需要这样,下面我们来实现
实现
QPushButton *getBackPushButtn=new QPushButton("找回密码");
QLineEdit *passwordLineEdit=new QLineEdit();
//密码框设置文本的外边距,由于QPushButton是在右边的,所以要设置
//QPushButton的大小,PS:注意要控制好QPushButton的大小
passwordLineEdit->setTextMargins(0,0,getBackPushButton->width(),0);
QHBoxLayout *layout=new QHBoxLayout();
layout->setContentsMargins(0,0,0,0);//设置外边距
//以右对齐的方式添加QWidget
layout->addWidget(getBackPushButton,0,Qt::AlignRight);
passwordLineEdit->setLayout(layout);
QHBoxLayout *layout2 = new QHBoxLayout();
layout2->addWidget(passwordLineEdit);
这样就可以实现了,当然要实现上图的下划线和文本密码,在这里不赘述。