Qt:登陆界面布局

系统管理员 2022-10-24 11:46 380阅读 0赞
  1. #include <QApplication>
  2. #include <QWidget>
  3. #include <QPushButton>
  4. #include <QLineEdit>
  5. #include <QHBoxLayout>
  6. #include <QGridLayout>
  7. #include <QLabel>
  8. int main(int argc, char *argv[])
  9. {
  10. QApplication app(argc, argv);
  11. QWidget w;
  12. QLineEdit *password;
  13. QGridLayout gLayout;
  14. gLayout.setColumnStretch(0, 1); //在第0行放置1根弹簧
  15. gLayout.setRowStretch(0, 1); //在第0列放置1根弹簧
  16. gLayout.setColumnStretch(3, 1); //在第0行放置1根弹簧
  17. gLayout.setRowStretch(4, 1); //在第0列放置1根弹簧
  18. gLayout.addWidget(new QLabel("Username:"), 1, 1);
  19. gLayout.addWidget(new QLineEdit(), 1, 2);
  20. gLayout.addWidget(new QLabel("password:"), 2, 1);
  21. gLayout.addWidget(password = new QLineEdit(), 2, 2);
  22. password->setEchoMode(QLineEdit::Password);
  23. QHBoxLayout *hBox;
  24. gLayout.addLayout(hBox = new QHBoxLayout, 3, 2);
  25. hBox->addStretch(1);
  26. hBox->addWidget(new QPushButton("登陆"), 1);
  27. w.setLayout(&gLayout);
  28. w.setWindowTitle("Hello world");
  29. w.show();
  30. return app.exec();
  31. }

0ff0ccf157ba5986ed3de84687f7346ea80.jpg

发表评论

表情:
评论列表 (有 0 条评论,380人围观)

还没有评论,来说两句吧...

相关阅读

    相关 嵌入式 QT 界面布局管理

    所谓布局,就是界面上组件的排列方式,使用布局可以使组件有 规则地分布,并且随着窗体大小变化自动地调整大小和相对位置。使用工具栏上的布局控制按钮时,只需在窗体上选中需要设计...