Qt之登陆界面布局

  • Post author:
  • Post category:其他


#include <QApplication>
#include <QWidget>
#include <QPushButton>
#include <QLineEdit>
#include <QHBoxLayout>
#include <QGridLayout>
#include <QLabel>
int main(int argc, char *argv[])
{
    QApplication app(argc, argv);

    QWidget w;


    QLineEdit *password;
    QGridLayout gLayout;
    gLayout.setColumnStretch(0, 1); //在第0行放置1根弹簧
    gLayout.setRowStretch(0, 1);    //在第0列放置1根弹簧
    gLayout.setColumnStretch(3, 1); //在第0行放置1根弹簧
    gLayout.setRowStretch(4, 1);    //在第0列放置1根弹簧
    gLayout.addWidget(new QLabel("Username:"), 1, 1);
    gLayout.addWidget(new QLineEdit(), 1, 2);
    gLayout.addWidget(new QLabel("password:"), 2, 1);
    gLayout.addWidget(password = new QLineEdit(), 2, 2);
    password->setEchoMode(QLineEdit::Password);
    QHBoxLayout *hBox;
    gLayout.addLayout(hBox = new QHBoxLayout, 3, 2);
    hBox->addStretch(1);
    hBox->addWidget(new QPushButton("登陆"), 1);
    w.setLayout(&gLayout);
    w.setWindowTitle("Hello world");
    w.show();
    return app.exec();
}

0ff0ccf157ba5986ed3de84687f7346ea80.jpg


转载于:https://my.oschina.net/u/3919756/blog/1944243