1.一个简单的QT程序(QPushButton)

  1. /* 应用程序抽象类 */
  2. #include <QApplication>
  3.  
  4. /*窗口类*/
  5. #include <QWidget>
  6.  
  7. /* 按钮 */
  8. #include <QPushButton>
  9.  
  10. int main(int argc, char* argv[])
  11. {
  12. QApplication app(argc, argv);
  13.  
  14. /* 构造一个窗口*/
  15. QWidget w;
  16.  
  17. /*显示窗口*/
  18. w.show();
  19.  
  20. /* 按钮也是个窗口 */
  21. QPushButton button;
  22. button.setText("Button");
  23. /* 窗口对象的父子关系,影响显示位置 */
  24. /* 没有父窗口的窗口,我们称之为主窗口 */
  25. button.setParent(&w);
  26. button.show();
  27.  
  28. /* 设置按钮的坐标位置 */
  29. button.setGeometry(, , , );
  30.  
  31. /* QT对C++的拓展 */
  32. // std::bind std::function
  33. QObject::connect(&button, SIGNAL(clicked()), &w, SLOT(close()));
  34.  
  35. w.setWindowTitle("Hello World");
  36.  
  37. /*在exec中有一个消息循环*/
  38. return app.exec();
  39. }

PS:需要在.pro文件中声明

  1. SOURCES += \
  2. qgridlayoutdemo.cpp
  3.  
  4. QT += gui widgets

才能正常运行。

运行结果:

2.QLineEdit, QLabel, QGridLayout, QHBoxLayout的用法

  1. #include <QApplication>
  2. #include <QWidget>
  3. #include <QGridLayout>
  4. #include <QLabel>
  5. #include <QLineEdit>
  6. #include <QTextEdit>
  7. #include <QHBoxLayout>
  8. #include <QPushButton>
  9.  
  10. int main(int argc, char *argv[])
  11. {
  12.  
  13. QApplication app(argc, argv);
  14. QWidget w;
  15.  
  16. QGridLayout *layout = new QGridLayout;
  17. layout->setColumnStretch(, );
  18. layout->setColumnStretch(, );
  19. layout->setColumnStretch(, );
  20. layout->setColumnStretch(, );
  21. layout->setColumnStretch(, );
  22.  
  23. QLabel *lb_first_name = new QLabel("First Name:");
  24. QLineEdit *ed_first_name = new QLineEdit;
  25. QLabel *lb_last_name = new QLabel("Last Name:");
  26. QLineEdit *et_last_name = new QLineEdit;
  27. QLabel *lb_sex = new QLabel("Sex:");
  28. QLineEdit *et_sex = new QLineEdit;
  29. QLabel *lb_birthday = new QLabel("Birthday:");
  30. QLineEdit *et_birthday = new QLineEdit;
  31. QLabel *lb_address = new QLabel("Address:");
  32. QTextEdit *te_edit = new QTextEdit;
  33.  
  34. layout->addWidget(lb_first_name, , );
  35. layout->addWidget(ed_first_name, , );
  36. layout->addWidget(lb_last_name, , );
  37. layout->addWidget(et_last_name, , );
  38. layout->addWidget(lb_sex, , );
  39. layout->addWidget(et_sex, , );
  40. layout->addWidget(lb_birthday, , );
  41. layout->addWidget(et_birthday, , );
  42. layout->addWidget(lb_address, , );
  43. layout->addWidget(te_edit, , , , );
  44.  
  45. // QGridLayout layout;
  46. // QLineEdit *pwd;
  47.  
  48. // layout.setColumnStretch(0, 1);
  49. // layout.setColumnStretch(3, 1);
  50. // layout.setRowStretch(0, 1);
  51. // layout.setRowStretch(4, 1);
  52.  
  53. // layout.addWidget(new QLabel("UserName:"), 1, 1);
  54. // layout.addWidget(new QLineEdit(), 1, 2);
  55. // layout.addWidget(new QLabel("Password"), 2, 1);
  56. // layout.addWidget(pwd = new QLineEdit(), 2, 2);
  57.  
  58. // QHBoxLayout *hBoxLayout;
  59. // layout.addLayout(hBoxLayout = new QHBoxLayout(), 3, 2);
  60. // hBoxLayout->addStretch(1);
  61. // hBoxLayout->addWidget(new QPushButton("Login"));
  62.  
  63. // pwd->setEchoMode(QLineEdit::Password);
  64.  
  65. w.setLayout(layout);
  66. w.setWindowTitle("QGridLayoutDemo");
  67. w.show();
  68.  
  69. return app.exec();
  70. }

运行结果:

QT学习记录(1)-控件 QPushButton, QLineEdit, QLabel, QHBoxLayout, QGridLayout的更多相关文章

  1. QT学习记录之控件布局

    作者:朱金灿 来源:http://blog.csdn.net/clever101 想到控件布局就会想到Windows编程中要实现对话框上的控件的合理布局是一件多么艰难的事情.对此QT提出了一个很方便的 ...

  2. asp.net学习之Repeater控件

    asp.net学习之Repeater控件 文章摘自:http://www.cnblogs.com/shipfi/archive/2009/10/19/1585703.html Repeater控件和D ...

  3. asp.net学习之数据绑定控件、数据源控件概述

    原文:asp.net学习之数据绑定控件.数据源控件概述 1.asp.net数据绑定控件分为三大类,每个类分别进行详细:      ● 列表式数据绑定控件: 列表式数据绑定控件常用来在一个表格内的一个字 ...

  4. asp.net学习之 数据绑定控件--表格绑定控件

    原文:asp.net学习之 数据绑定控件--表格绑定控件     数据绑定 Web 服务器控件是指可绑定到数据源控件,以实现在 Web 应用程序中轻松显示和修改数据的控件.数据绑定 Web 服务器控件 ...

  5. Swift学习之熟悉控件

    最近是比较清闲一些的,对于一个开发者来说,这也是一个很好的充电机会.以前做项目都是使用Objective-C去开发,但我们都知道,Swift语言从2014年的出现到现在,一步一步变的完善,渐渐变的受欢 ...

  6. asp.net学习之DataList控件

    asp.net学习之DataList控件   DataList控件与Repeater控件一样由模板驱动,与Repeater控件不同的是: DataList控件默认输出是一个HTML表格.DataLis ...

  7. 在Qt中使用ActiveX控件

    Qt的windows商业版本提供了ActiveQt这个framework,使用这个组件我们可以在Qt中使用ActiveX控件,并且也开发基于Qt的ActiveX控件.ActiveQt包含了两个组件QA ...

  8. asp.net学习之 数据绑定控件--List数据绑定控件

    原文:asp.net学习之 数据绑定控件--List数据绑定控件 List控件(如 CheckBoxList.DropDownList.ListBox 和 RadioButtonList 类)继承自L ...

  9. Qt 开发 MS VC 控件终极篇

    Qt 开发 MS VC 控件终极篇 1. 使用 MSVC2015 通过项目向导创建 Qt ActiveQt Server 解决方案 项目配置:以下文件需要修改 1. 项目属性页->项目属性-&g ...

随机推荐

  1. PHP高级教程-安全邮件

    PHP Secure E-mails 在上一节中的 PHP e-mail 脚本中,存在着一个漏洞. PHP E-mail 注入 首先,请看上一章中的 PHP 代码: <html> < ...

  2. ssh2的application.xml配置文件配置详解

    ssh2的application.xml配置文件配置详解   1.导入其他的配置文件.在ssh项目中可以导入其他的配置文件,导入的格式为: <import resource="clas ...

  3. 【二】Drupal 入门之新建主题

    Drupal 的模板是以  *.tpl.php  命名的 php 文件 1.在Drupal中,默认模板路径为 moudles/system 这就是我们为什么还没有制作模板 Drupal 就能够正常显示 ...

  4. GNU与Linux

    GNU是自由软件之父 Richard Stallman在1984年组织开发的一个完全基于自由软件的软件体系,与此相应的有一分通用公共许可证(General Public License,简称GPL). ...

  5. 从零开始学做微信小程序,看这些就够了!

    随着正式开放公测,微信小程序再次万众瞩目,越来越多的企业和个人涌入到小程序开发的大军中.小程序究竟是什么?适合做小程序的产品有哪些?做小程序需要提前准备什么?如何零基础学做小程序?此文,将列出OSC上 ...

  6. awk打印倒数第2列

    cat 1-iplist.txt | awk '{ print $(NF-2) }'|wc 实际示例: 打印nginx日志中 变量request_time超过3秒的日志信息 [root@datalin ...

  7. cxf使用wsdl文件生成代码

    1.先下载cxf包 http://cxf.apache.org/download.html,现在cxf包.(下载资源就有) 2.解压缩包,通过cmd命令进入到bin目录下(cd cxf\bin的路径) ...

  8. hdu1695 容斥原理 莫比乌斯反演

    给定两个数b,d,问[1,b]和[1,d]区间上有多少对互质的数.(x,y)和(y,x)算一个. 对于[1,b]部分,用欧拉函数直接求.对于大于b的部分,求n在[1,b]上有多少个互质的数,用容斥原理 ...

  9. invalid configuration x86_64-unknown-linux-gnu' machine x86_64-unknown' not recognized

    转载自:http://blog.csdn.net/php_boy/article/details/7382998 前两天在装机器软件的时候, 出现了下面的错误, invalid configurati ...

  10. 【js】正则表达式(II)

    JavaScript中提供了一个名为RegExp的对象来完成有关正则表达式的操作和功能,每一条正则表达式模式对应一个RegExp对象实例. 在JavaScript中,有两种方式可以创建RegExp对象 ...