QT 入门 -QApplication QPushButton QDialog Ui类型的手工使用
QT
1.工具
assistant 帮助文档
qtconfig QT配置工具
qmake QT的make与项目文件智能创建工具
uic UI界面的设计文件的编译工具
moc moc代码创建工具
designer UI设计工具
2.QT 的模块
qtcore
qtgui
qtnetwork
qtsvg
qtopengl
3.第一个QT程序
1.QT编程模型
2.QT程序编译过程
3.QT的项目组织
1. QT是C++程序
2. QT程序启动QT的环境QApplication
代码:
#include<QApplication>
#include<QDialog>
int main(int args , char **argv)
{
QApplicationapp(args , argv);
QDialog dlg;
dlg.setVisible(true);
return app.exec();//等待子线程结束
}
编译:1.qmake–project
生成一个.pro的文件(项目配置文件)
2.qmake xxx.pro
生成makefile文件
3.make
4.执行
4.*pro文件
TEMPLATE=
:app 表明为应用程序
:lib 表明是库
SOURCES=
:cpp文件1 cpp文件2 cpp文件3
:\续行符号
HEADERS=
:h头文件
CONFIG= 影响gcc的选项
:release (-o)|debug(-g调试)
:warn_on | warn_off (-Wall -w 警告)
: qt (表示qt应用,会自动加 qt库) | opengl
:shared| static动态,静态库,只有TEMPLATE指定为lib才管用
QT=(该变量在config=qt才有意义)
:core
:gui
:network
:opengl
:svg
:xml
:sql
TARGET=
:输出的文件名(-o 输出文件名)
LIBS=用户指定库(用户自己的库)
FORMS=ui文件
程序2:
#include<QApplication>
#include<QWidget>
int main(int args,char **argv)
{
QApplicationapp(args,argv);
QWidget win;
win.setVisable(true);
returnapp.exec();
}
创建文件2:demo.pro
TEMPLATE=app
SOURCES=main.cpp
HEADERS=
CONFIG=qt release
QT=core gui
TARGET=main
直观认识QT
封装与帮助文档的使用
文档的组成部分:
1. 模块
2.类作用简单描述
3.头文件
4.父类与派生类
5.构造器/析构器()
6.共有函数
7.属性
例子:QPushButton
#include<QApplication>
#include<QWidget>
#include<QPushButton>
int main(int args,char **argv)
{
QApplication app(args,argc);
QWidget win;
win.resize(400,300);
win.move( (1024-400)/2,(768-300)/2); //设置窗体的大小和位置
win.setVisible(true);
QPushButton btn(&win); //pushbutton的构造函数参数为父窗体的指针
btn.resize(100,30); //设置button大小
btn.move(10,10);
btn.setText(“ok”);
btn.setVisible(true);
app.exec();
}
2. 乱码处理-上个程序的button中text,如果是中文会出现乱码
QT提供翻译机制
QTTextCodec类
例子:
#include<QApplication>
#include<QDialog>
#include<QPushButton>
#include<QTextCodec>
int main(int args, char **argv)
{
QApplication app(args,argv);
QTextCodec *codec=QTextCodec::codecForName(“gb2312”);
//设置应用程序的编码:gb2312 codecForName静态成员函数
QTextCodec::setCodecForTr(codec); //把设置的编码设置到环境中
QDialog dlg;
dlg.resize(400,300);
dlg.move((1024-400)/2,(768-300)/2);
QPushButton btn(&dlg);
btn.resize(100,30);
btn.move(100,100);
btn.setText(QObject::tr(“确定”)); //在使用中文的地方翻译
btn.setVisible(true);
dlg.setVisible(true);
return app.exec();
}
例子:QLineEditS
#include<QApplication>
#include<QDialog>
#include<QLineEdit>
int main(int args,char ** argv)
{
QApplication app(args,argv);
QTextCodec *codec=QTextCodec::codecForName(“gb2312”);
QTextCodec::setCodecForTr(codec);
QDialog dlg;
dlg.resize(400,300);
dlg.move((1024-400)/2 , (768-300)/2);
QLineEdit edit;
edit.resize(100,30);
edit.move(100,100);
edit.setVisible(true);
dlg.setVisible(true);
return app.exec();
}
3.代码组织
以窗体为基本单位的封装
案例:
登陆
QDialog
QPushButton
QLabel
QLineEdit
代码:
main.cpp
#include<QApplication>
#include<QTextCodec>
#include “logindlg.h”
int main(int args,char **argv)
{
QApplication app(args , argv);
QTextCodec *codec=QTextCodec::codecForName(“gb2312”);
QTextCodec::setCodecForTr(codec);
LoginDialog dlg;
dlg.resize(400,300);
dlg.setVisible(true);
return app.exec();
}
logindlg.h
#ifndef LOGIN_DLG_H
#define LOGIN_DLG_H
#include<QDialog>
#include<QLabel>
#include<QLineEdit>
#include<QPushButton>
class LoginDialog : public QDialog
{
public:
LoginDialog(QWidget * parent=NULL);
private:
QLabel *lbluser;
QLabel *lblpass;
QLineEdit *edtuser;
QLineEdit *edtpass;
QPushButton *btnlogin;
QPushButton *btncancel;
};
#endif
Logindlg.cpp
#include “logindlg.h”
LoginDialog::LoginDialog(QWidget * parent):QDialog(parent)
{
lbluser=new QLablel(this);
lblpass=new QLabel(this);
this->resize(400,300);
this->move((1024-400)/2,(768-300)/2);
lbluser->resize(100,30);
lbluser->move(50,40);
lblpass->resize(100,30);
lblpass->move(50,100);
lbluser->setText(QObject::tr(“用户:”));
lblpass->setText(QObject::tr(“口令:”));
edtuser=new QLineEdit(this);
edtpass=new QLineEdit(this);
edtuser->resize(200,30);
edtuser->move(150,40);
edtpass->resize(200,30);
edtpass->move(150,100);
btnlogin = new QPushButton(this);
btncancel=new QPushButton(this);
btnlogin->resize(60,30);
btnlogin->move(90,210);
btncancel->resize(60,30);
btncancel->move(250,210);
btnlogin->setText(Qobject::tr(“登录”));
btncancel->setText(QObject::tr(“取消”));
}
3. QT的界面设计器
designer 可视化编辑器
3.1. 工具视图:
用户设计区
工具箱
资源管理器
属性编辑器(ctrl+i)
动作编辑器
信号槽编辑器
对象察看器(选择对象)
3.2. 保存文件
*.ui
3.3.编辑属性
1.文本属性
2.对象名属性
3.字体属性
3.4. 编辑组件
-> <-方向
shift+方向 大小改变
ctrl+
shift+ctrl+
3.5.打开ui文件
ui是xml文本文件
3.6.使用ui文件
自动使用
手工使用
uic编译ui文件 : 例如:uic login.ui –o login.h
产生:c++头文件
Ui_对象名的类
Ui::对象名的类 Ui命名空间
以上两种使用对象的方法
类的构造器:没有(缺省构造器)
类的方法:setUi(QDialog *);
3.7.使用UI类型
Main.cpp
#include<QApplication>
#include “dlglogin.h”
int main(int args, char ** argv)
{
QApplication app(args,argv);
DlgLogin dlg;
dlg.setVisible(true);
return app.exec();
}
dlglogin.h
#ifndef MY_LOGINDLG_H
#define MY_LOGINDLG_H
#include<QDialog>
#include “login.h”
class DlgLogin : public QDialog
{
private;
Ui_LoginDialog *ui;
public:
DlgLogin(QDialog * parent=NULL);
~DlgLogin();
}
#endif
dlglogin.cpp
#include “dlglogin.h”
DlgLogin::DlgLogin(QDialog *parent):QDialog(parent)
{
ui = new Ui_LoginDialog;
ui->setupUi(this);
}
DlgLogin::~DlgLogin()
{
delectui;
}
QT 入门 -QApplication QPushButton QDialog Ui类型的手工使用的更多相关文章
- Qt入门之基础篇 ( 二 ) :Qt项目建立、编译、运行和发布过程解析
转载请注明出处:CN_Simo. 题解: 本篇内容主讲Qt应用从创建到发布的整个过程,旨在帮助读者能够快速走进Qt的世界. 本来计划是讲解Qt源码静态编译,如此的话读者可能并不能清楚地知道为何要静态编 ...
- Qt入门-layout布局
开发一个图形界面应用程序,界面的布局影响到界面的美观.在设计一个界面之前,应该考虑到开发的界面可能给不用的用户使用,而用户的屏幕大小.纵横比例.分辨率可能不同,界面还可能是可缩放的,程序应该可以适应这 ...
- Qt入门(5)——用Qt控件创建一个电话本界面
具体实现步骤: 一.首先用 Qt Designer 创建一个两张图的对话框,分别保存为listdialog.ui和editdialog.ui文件 要注意其中各个空间对应的名称修改好 二.新建一个Qt应 ...
- Qt入门(4)——Qt常见控件
Qt提供了大量的内建控件及通用对话框可满足程序员的绝大部分要求.我们将对这些控件和对话框作一个大概的介绍. 1. QLabel 定义 QLabel* m_labelOrdered = newQLabe ...
- [QT]给QApplication安装事件过滤器 app.installEventFilter
Qt的事件处理有5种级别: 1. 重写控件的事件处理函数:如重写keyPressEvent(),mousePressEvent()和paintEvent(),这是最常用的事件处理方法,我们已 ...
- QT入门学习
第一个QT程序 #include<QApplication> #include<QDialog> #include<QLabel> #include<QTex ...
- 第15.25节 PyQt(Python+Qt)入门学习:Model/View开发实战--使用QTableView展示Excel文件内容
老猿Python博文目录 专栏:使用PyQt开发图形界面Python应用 老猿Python博客地址 一.概述 在前面的订阅专栏<第十九章.Model/View开发:QTableView的功能及属 ...
- 第15.12节PyQt(Python+Qt)入门学习:可视化设计界面组件布局详解
一.引言 在Qt Designer中,在左边部件栏的提供了界面布局相关部件,如图: 可以看到共包含有四种布局部件,分别是垂直布局(Vertical Layout).水平布局(Horizontal La ...
- Qt入门学习——Qt 5 帮助文档的使用
Qt入门学习——Qt 5 帮助文档的使用 学习图形界面开发,肯定离不开帮助文档的使用,因为它不像 C 语言那样就那么几个函数接口,图形接口的接口可以用海量来形容,常用的我们可能能记住,其它的真的没有必 ...
随机推荐
- objective-C学习笔记(七) 字符串处理
字符串NSString NSString 是一个Unicode编码,16位字符的字符序列. NSString 是一个类,拷贝时需要注意. 初始化方法:字面量初始化.初始化器.工厂方法. NSStrin ...
- MVC下载Excel
方法1: public ActionResult DownExcel() { var stream = list.Select(p => new { p.UserName, p.Mobile, ...
- [Jobdu] 题目1367:二叉搜索树的后序遍历序列
题目描述: 输入一个整数数组,判断该数组是不是某二叉搜索树的后序遍历的结果.如果是则输出Yes,否则输出No.假设输入的数组的任意两个数字都互不相同. 输入: 每个测试案例包括2行: 第一行为1个整数 ...
- HDU 1695 GCD(欧拉函数+容斥原理)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1695 题意:x位于区间[a, b],y位于区间[c, d],求满足GCD(x, y) = k的(x, ...
- (转)C++中extern “C”含义深层探索
(转)C++中extern “C”含义深层探索 转自: http://www.cppblog.com/Macaulish/archive/2008/06/17/53689.html 1.引言 C++语 ...
- JS性能
获取以下属性 会等待对应元素渲染完成 才继续执行 * offsetTop, offsetLeft, offsetWidth, offsetHeight* scrollTop, scrollLeft ...
- 【转】C++ stringstream介绍,使用方法与例子
原文来自:http://www.cnblogs.com/lancidie/archive/2010/12/03/1895161.html C++引入了ostringstream.istringstre ...
- java.lang.UnsupportedClassVersionError: Bad version number in .class file 解决方案
在Myeclipse中运行小应用程序时出现如下异常的解决办法 java.lang.UnsupportedClassVersionError: Bad version number in .class ...
- 提高IOS开发效率的常用网站、开源类库及工具
时间过得很快,学习iOS也已经2年左右了.在这里整理一下,在平台平常开发过程中使用比较多的开源类库.网站与工具吧! 一.网站: UI网站: 1.https://www.cocoacontrols.co ...
- beini破解无线
软件介绍 当你的笔记本有无线网卡却不能上网的时刻,也许你会很焦急. 又或许你的隔壁就有无线网络可以接的时刻,但你却由于米有密码而不能上网.下面我将简介一款可以令你惊讶的软件,奶瓶 有了奶瓶以上疑问都可 ...