QT学习记录(1)-控件 QPushButton, QLineEdit, QLabel, QHBoxLayout, QGridLayout
1.一个简单的QT程序(QPushButton)
/* 应用程序抽象类 */
#include <QApplication> /*窗口类*/
#include <QWidget> /* 按钮 */
#include <QPushButton> int main(int argc, char* argv[])
{
QApplication app(argc, argv); /* 构造一个窗口*/
QWidget w; /*显示窗口*/
w.show(); /* 按钮也是个窗口 */
QPushButton button;
button.setText("Button");
/* 窗口对象的父子关系,影响显示位置 */
/* 没有父窗口的窗口,我们称之为主窗口 */
button.setParent(&w);
button.show(); /* 设置按钮的坐标位置 */
button.setGeometry(, , , ); /* QT对C++的拓展 */
// std::bind std::function
QObject::connect(&button, SIGNAL(clicked()), &w, SLOT(close())); w.setWindowTitle("Hello World"); /*在exec中有一个消息循环*/
return app.exec();
}
PS:需要在.pro文件中声明
SOURCES += \
qgridlayoutdemo.cpp QT += gui widgets
才能正常运行。
运行结果:

2.QLineEdit, QLabel, QGridLayout, QHBoxLayout的用法
#include <QApplication>
#include <QWidget>
#include <QGridLayout>
#include <QLabel>
#include <QLineEdit>
#include <QTextEdit>
#include <QHBoxLayout>
#include <QPushButton> int main(int argc, char *argv[])
{ QApplication app(argc, argv);
QWidget w; QGridLayout *layout = new QGridLayout;
layout->setColumnStretch(, );
layout->setColumnStretch(, );
layout->setColumnStretch(, );
layout->setColumnStretch(, );
layout->setColumnStretch(, ); QLabel *lb_first_name = new QLabel("First Name:");
QLineEdit *ed_first_name = new QLineEdit;
QLabel *lb_last_name = new QLabel("Last Name:");
QLineEdit *et_last_name = new QLineEdit;
QLabel *lb_sex = new QLabel("Sex:");
QLineEdit *et_sex = new QLineEdit;
QLabel *lb_birthday = new QLabel("Birthday:");
QLineEdit *et_birthday = new QLineEdit;
QLabel *lb_address = new QLabel("Address:");
QTextEdit *te_edit = new QTextEdit; layout->addWidget(lb_first_name, , );
layout->addWidget(ed_first_name, , );
layout->addWidget(lb_last_name, , );
layout->addWidget(et_last_name, , );
layout->addWidget(lb_sex, , );
layout->addWidget(et_sex, , );
layout->addWidget(lb_birthday, , );
layout->addWidget(et_birthday, , );
layout->addWidget(lb_address, , );
layout->addWidget(te_edit, , , , ); // QGridLayout layout;
// QLineEdit *pwd; // layout.setColumnStretch(0, 1);
// layout.setColumnStretch(3, 1);
// layout.setRowStretch(0, 1);
// layout.setRowStretch(4, 1); // layout.addWidget(new QLabel("UserName:"), 1, 1);
// layout.addWidget(new QLineEdit(), 1, 2);
// layout.addWidget(new QLabel("Password"), 2, 1);
// layout.addWidget(pwd = new QLineEdit(), 2, 2); // QHBoxLayout *hBoxLayout;
// layout.addLayout(hBoxLayout = new QHBoxLayout(), 3, 2);
// hBoxLayout->addStretch(1);
// hBoxLayout->addWidget(new QPushButton("Login")); // pwd->setEchoMode(QLineEdit::Password); w.setLayout(layout);
w.setWindowTitle("QGridLayoutDemo");
w.show(); return app.exec();
}
运行结果:

QT学习记录(1)-控件 QPushButton, QLineEdit, QLabel, QHBoxLayout, QGridLayout的更多相关文章
- QT学习记录之控件布局
作者:朱金灿 来源:http://blog.csdn.net/clever101 想到控件布局就会想到Windows编程中要实现对话框上的控件的合理布局是一件多么艰难的事情.对此QT提出了一个很方便的 ...
- asp.net学习之Repeater控件
asp.net学习之Repeater控件 文章摘自:http://www.cnblogs.com/shipfi/archive/2009/10/19/1585703.html Repeater控件和D ...
- asp.net学习之数据绑定控件、数据源控件概述
原文:asp.net学习之数据绑定控件.数据源控件概述 1.asp.net数据绑定控件分为三大类,每个类分别进行详细: ● 列表式数据绑定控件: 列表式数据绑定控件常用来在一个表格内的一个字 ...
- asp.net学习之 数据绑定控件--表格绑定控件
原文:asp.net学习之 数据绑定控件--表格绑定控件 数据绑定 Web 服务器控件是指可绑定到数据源控件,以实现在 Web 应用程序中轻松显示和修改数据的控件.数据绑定 Web 服务器控件 ...
- Swift学习之熟悉控件
最近是比较清闲一些的,对于一个开发者来说,这也是一个很好的充电机会.以前做项目都是使用Objective-C去开发,但我们都知道,Swift语言从2014年的出现到现在,一步一步变的完善,渐渐变的受欢 ...
- asp.net学习之DataList控件
asp.net学习之DataList控件 DataList控件与Repeater控件一样由模板驱动,与Repeater控件不同的是: DataList控件默认输出是一个HTML表格.DataLis ...
- 在Qt中使用ActiveX控件
Qt的windows商业版本提供了ActiveQt这个framework,使用这个组件我们可以在Qt中使用ActiveX控件,并且也开发基于Qt的ActiveX控件.ActiveQt包含了两个组件QA ...
- asp.net学习之 数据绑定控件--List数据绑定控件
原文:asp.net学习之 数据绑定控件--List数据绑定控件 List控件(如 CheckBoxList.DropDownList.ListBox 和 RadioButtonList 类)继承自L ...
- Qt 开发 MS VC 控件终极篇
Qt 开发 MS VC 控件终极篇 1. 使用 MSVC2015 通过项目向导创建 Qt ActiveQt Server 解决方案 项目配置:以下文件需要修改 1. 项目属性页->项目属性-&g ...
随机推荐
- JavaScript二(第一个js程序)
一.<script>xxxx</script>标签解析 1.charset :可选,表示通过src属性指定的字符集,由于大多数浏览器忽略它,所以很少有人用它2.defer:可选 ...
- PHPstorm自定义快捷键
Ctrl+alt+S 打开设置 PHPstorm 设置 PHPstorm 主题安装 自定义快捷键设置 ·全屏 F11 ·另外一种全屏alt+F11 Database数据库管理 alt+d Termin ...
- UsageLog4j
迁移时间:2017年5月21日09:42:46CreateTime--2017年1月2日09:35:55Author:Marydon原文链接:http://www.360doc.com/conte ...
- centos/rhel最小化安装图形化
图形化,一般不再服务器中安装.为了提升系统的利用率. centos的yum源对应centos的源 RHEL的yum源对应RHEL的源 我演示的Centos6.5,我挂载的RHEL6.5的源.作为软件源 ...
- 关于PHP中的opcode
简介 1.当Zend engine解释器完成对脚本代码的分析后,便将它们生成可以直接运行的中间代码,也称为操作码(Operate Code,opcode),opcode是一个四元组,(opcode, ...
- nyoj----522 Interval (简单树状数组)
Interval 时间限制:2000 ms | 内存限制:65535 KB 难度:4 描述 There are n(1 <= n <= 100000) intervals [ai, ...
- tensorflow的警告
W c:\tf_jenkins\home\workspace\release-win\device\cpu\os\windows\tensorflow\core\platform\cpu_featur ...
- php 类和对象
⾯向对象是⼀种编程范式,它将对象作为程序的基本单元,将程序和数据封装起来, 以此来提⾼程序的重⽤性.灵活性和可扩展性. ⽬前很多语⾔都⽀持⾯向对象编程,既然对象对象是⼀种范式,其实这就和具体的编程语⾔ ...
- Squid调试和故障处理
http://blog.zhdata.com/tag/squid第16章 调试和故障处理 16.1 一些通用问题 在讨论通用debug前,我先提起一些经常发生的问题. 16.1.1 “Failed t ...
- Android干坏事——禁止设备休眠
实现这一功能的方法有两种,一种是在Manifest.xml文件里面声明,一种是在代码里面修改LayoutParams的标志位.具体如下: 1.在Manifest.xml文件里面用user-permis ...