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的更多相关文章

  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. 【转】TCP/IP详解学习笔记(一)

      TCP/IP详解学习笔记   这位仁兄写得太好了. http://blog.csdn.net/goodboy1881/category/204448.aspx TCP/IP详解学习笔记(13)-T ...

  2. CAE医疗综合视听中心管理系统

    http://caehealthcare.com/eng/audiovisual-solutions/learning-space https://vimeo.com/108897296http:// ...

  3. bzoj3675【APIO2014】序列切割

    3675: [Apio2014]序列切割 Time Limit: 40 Sec  Memory Limit: 128 MB Submit: 1468  Solved: 607 [Submit][Sta ...

  4. css before和after伪元素应用

    1.说明 ":before" 伪元素可以在元素的内容前面插入新内容. ":after" 伪元素可以在元素的内容之后插入新内容. 伪元素默认展示为inline, ...

  5. 30、java中递归算法

    1.已知有一个数列f(0)=1,f(1)=4,f(n+2)=2*f(n+1)+f(n),其中n是大于0的正数,求f(10)的值. 分析:设x=n+2 => f(x)=2*f(n-1)+f(n-2 ...

  6. Windows下安装OpenSSL及其使用

    方法一: Windows binaries can be found here: http://www.slproweb.com/products/Win32OpenSSL.html You can ...

  7. 开源大数据技术专场(上午):Spark、HBase、JStorm应用与实践

    16日上午9点,2016云栖大会“开源大数据技术专场” (全天)在阿里云技术专家封神的主持下开启.通过封神了解到,在上午的专场中,阿里云高级技术专家无谓.阿里云技术专家封神.阿里巴巴中间件技术部高级技 ...

  8. PmExceptionController

    package main.java.com.zte.controller.system; import java.util.ArrayList; import java.util.List; impo ...

  9. eclipse新建maven工程的各种坑

    尽量按照最后强烈推荐的那篇创建maven工程.  1.jsp文件头报错 2.xml配置文件头红叉 3.Archive for required library...blabla 4.pom依赖出错 5 ...

  10. idea编辑区光标问题

    本文转自:http://blog.csdn.net/shaoyezhangliwei/article/details/48735417 今天在用idea的情况下 ,莫名闪退了 ,重新打开的时候发现 光 ...