《Qt入门培训》PPT课件.ppt
《《Qt入门培训》PPT课件.ppt》由会员分享,可在线阅读,更多相关《《Qt入门培训》PPT课件.ppt(110页珍藏版)》请在三一办公上搜索。
1、,.,Qt入门培训,Qt introduction,Qt简介Qt的使用Qt深入理解Qt的应用,Qt简介,什么是Qt?,什么是Qt?,原来用作用户界面开发,现可用作所有的开发例如:Databases,XML,WebKit,multimedia,networking,OpenGL,scripting,non-GUI.,”Qt 是一个用C+编写的跨平台开发框架.”,什么是Qt?,Qt由模块构建,QtCore,Phonon,QtXmlPatterns,QtXml,QtWebKit,QtSvg,QtSql,QtScript,QtOpenVG,QtOpenGL,QtNetwork,QtMultimedia
2、,QtGui,什么是QT?,Qt用宏(macros)和内省(introspection)扩展了C+所有的代码仍然是简明C+,foreach(int value,intList)QObject*o=new QPustButton;o-metaObject()-className();/返回”QPushButton”connect(button,SIGNAL(clicked(),window,SLOT(close();,Qt的目的,一次编写,到处编译根据不同平台的本地观感生成相应的本地应用简单地使用API,高开发效率,开放性,使用有趣,Qt的历史,1990,1991,1994,1999,2001,
3、Haavard 和Eirik灵感闪现,开始设计,并提出信号和槽的概念,1993,开发出Qt的第一个图形核心,命名为Qt,并建立“奇趣科技”,1995,签订第一个合同,开始快速发展。,1997,Qt1.2发布,并且用于开发KDE。,Qt 2.0发布,Qt 3.0发布。,2005,Qt 4.0发布,2008,Nokia收购奇趣科技,Qt的跨平台桌面平台,WindowsMac OS XLinux/Unix X11,Qt的跨平台嵌入式平台,Windows CESymbianMaemo嵌入式Linux,Qt的授权,LGPL 免费你的应用程序可以是开源的或者是不开源的对Qt的修改,必须反馈到社区GPL 免
4、费你的应用程序必须是开源的对Qt的修改,必须反馈到社区商业的 收费你的应用程序可以是不开源 的对Qt的修改,可以不开源,Qt简介Qt的使用Qt深入理解Qt的应用,Qt的代码结构-Hello World,Qt的代码结构-Hello World,#include#include int main(int argc,char*argv)QApplication app(argc,argv);QLabel l(Hello World!);l.show();return app.exec();,Qt的代码结构-Hello World,#include#include int main(int argc,
5、char*argv)QApplication app(argc,argv);QLabel l(Hello World!);l.show();return app.exec();,Qt的代码结构-Hello World,#include#include int main(int argc,char*argv)QApplication app(argc,argv);QLabel l(Hello World!);l.show();return app.exec();,Qt的代码结构-Hello World,#include#include int main(int argc,char*argv)QA
6、pplication app(argc,argv);QLabel l(Hello World!);l.show();return app.exec();,Qt的代码结构-Hello World,#include#include int main(int argc,char*argv)QApplication app(argc,argv);QLabel l(Hello World!);l.show();return app.exec();,Qt开发工具集,Qt CreatorQt DesignerQt LinguistQt AssisantQt Demos,信号(Signal)与槽(Slot)初
7、探,QT提供的一种在对象间进行通讯的技术。动态地或松散地将事件和状态变化联系起来。信号和槽机制是使Qt运作的元素。,信号(Signal)与槽(Slot)初探,类似于windows中的消息和消息响应都是通过C+类成员函数实现的信号和槽是通过连接实现相互关联的包含信号或槽的类必须从QObject继承,信号(Signal)与槽(Slot)初探,emit clicked();,信号(Signal)与槽(Slot)初探,private slots:void on_addButton_clicked();void on_deleteButton_clicked();,connect(clearButton
8、,SIGNAL(clicked(),listWidget,SLOT(clear();,connect(addButton,SIGNAL(clicked(),this,SLOT(.);,2x,clear();,信号(Signal)与槽(Slot)初探,.emit clicked();.,.emit clicked();.,.emit clicked();.,QString newText=QInputDialog:getText(this,Enter text,Text:);if(!newText.isEmpty()ui-listWidget-addItem(newText);,foreach(
9、QListWidgetItem*item,ui-listWidget-selectedItems()delete item;,clear();,信号(Signal)与槽(Slot)初探,class Employee:public QObjectQ_OBJECTpublic:Employee();int salary()const;public slots:void setSalary(int newSalary);signals:void salaryChanged(int newSalary);private:int mySalary;emit salaryChanged(50);,信号和槽
10、的声明:,信号(Signal)与槽(Slot)初探,信号(Signal)与槽(Slot)初探,信号与槽机制只能用在继承于QObject的类。槽可以返回值,但通过联接返回时不能有返回值,槽以一个普通的函数实现,可以作为普通函数调用。信号总是返回空,信号总是不必实现 一个信号可以连接到多个槽,但槽的调用顺序不确定。信号和槽需要具有相同的参数列表;如果信号的参数比槽多,那么多余的参数会被忽略;如果参数列表不匹配,Qt会产生运行时错误信息,信号和槽 vs 回调,回调(callback)是一个函数指针,当一个事件发生时被调用,任何函数都可以被安排作为回调。没有类型安全总是以直接调用方式工作信号和槽的方式
11、更加动态一个更通用的机制更容易互连两个已存在的类相关类之间涉及更少的知识共享,用户界面设计,用户界面由特定的部件(widget)构建,用户界面设计三种方式,1.绝对定位(absolute positioning)最粗劣的方式对部件的大小、位置进行硬编码2.手工布局(manual layout)绝对位置,但通过resizeEvent()方法改变大小3.布局管理器(layout managers)部件放置在布局管理器中,使界面更具弹性。,布局管理器的优点?,让部件适应内容让部件适应翻译变化让部件适应用户设置,布局管理,几种可用的布局布局管理器和部件“协商”各个部件大小与位置弹簧可以用来填充空白处,
12、QGridLayout,QVBoxLayout,QHBoxLayout,布局管理器示例,对话框由多层的布局管理器和部件组成两种方式:代码实现,使用设计器,布局管理器代码实现,QVBoxLayout*outerLayout=new QVBoxLayout(this);QHBoxLayout*topLayout=new QHBoxLayout();topLayout-addWidget(new QLabel(Printer:);topLayout-addWidget(c=new QComboBox();outerLayout-addLayout(topLayout);QHBoxLayout*gro
13、upLayout=new QHBoxLayout();.outerLayout-addLayout(groupLayout);outerLayout-addSpacerItem(new QSpacerItem(.);QHBoxLayout*buttonLayout=new QHBoxLayout();buttonLayout-addSpacerItem(new QSpacerItem(.);buttonLayout-addWidget(new QPushButton(Print);buttonLayout-addWidget(new QPushButton(Cancel);outerLayou
14、t-addLayout(buttonLayout);,布局管理器代码实现,QVBoxLayout*outerLayout=new QVBoxLayout(this);QHBoxLayout*topLayout=new QHBoxLayout();topLayout-addWidget(new QLabel(Printer:);topLayout-addWidget(c=new QComboBox();outerLayout-addLayout(topLayout);QHBoxLayout*groupLayout=new QHBoxLayout();.outerLayout-addLayout(
15、groupLayout);outerLayout-addSpacerItem(new QSpacerItem(.);QHBoxLayout*buttonLayout=new QHBoxLayout();buttonLayout-addSpacerItem(new QSpacerItem(.);buttonLayout-addWidget(new QPushButton(Print);buttonLayout-addWidget(new QPushButton(Cancel);outerLayout-addLayout(buttonLayout);,布局管理器代码实现,QVBoxLayout*o
16、uterLayout=new QVBoxLayout(this);QHBoxLayout*topLayout=new QHBoxLayout();topLayout-addWidget(new QLabel(Printer:);topLayout-addWidget(c=new QComboBox();outerLayout-addLayout(topLayout);QHBoxLayout*groupLayout=new QHBoxLayout();.outerLayout-addLayout(groupLayout);outerLayout-addSpacerItem(new QSpacer
17、Item(.);QHBoxLayout*buttonLayout=new QHBoxLayout();buttonLayout-addSpacerItem(new QSpacerItem(.);buttonLayout-addWidget(new QPushButton(Print);buttonLayout-addWidget(new QPushButton(Cancel);outerLayout-addLayout(buttonLayout);,布局管理器代码实现,QVBoxLayout*outerLayout=new QVBoxLayout(this);QHBoxLayout*topLa
18、yout=new QHBoxLayout();topLayout-addWidget(new QLabel(Printer:);topLayout-addWidget(c=new QComboBox();outerLayout-addLayout(topLayout);QHBoxLayout*groupLayout=new QHBoxLayout();.outerLayout-addLayout(groupLayout);outerLayout-addSpacerItem(new QSpacerItem(.);QHBoxLayout*buttonLayout=new QHBoxLayout()
19、;buttonLayout-addSpacerItem(new QSpacerItem(.);buttonLayout-addWidget(new QPushButton(Print);buttonLayout-addWidget(new QPushButton(Cancel);outerLayout-addLayout(buttonLayout);,布局管理器代码实现,QVBoxLayout*outerLayout=new QVBoxLayout(this);QHBoxLayout*topLayout=new QHBoxLayout();topLayout-addWidget(new QLa
20、bel(Printer:);topLayout-addWidget(c=new QComboBox();outerLayout-addLayout(topLayout);QHBoxLayout*groupLayout=new QHBoxLayout();.outerLayout-addLayout(groupLayout);outerLayout-addSpacerItem(new QSpacerItem(.);QHBoxLayout*buttonLayout=new QHBoxLayout();buttonLayout-addSpacerItem(new QSpacerItem(.);but
21、tonLayout-addWidget(new QPushButton(Print);buttonLayout-addWidget(new QPushButton(Cancel);outerLayout-addLayout(buttonLayout);,布局管理器代码实现,QHBoxLayout*groupLayout=new QHBoxLayout();QGroupBox*orientationGroup=new QGroupBox();QVBoxLayout*orientationLayout=new QVBoxLayout(orientationGroup);orientationLay
22、out-addWidget(new QRadioButton(Landscape);orientationLayout-addWidget(new QRadioButton(Portrait);groupLayout-addWidget(orientationGroup);QGroupBox*colorGroup=new QGroupBox();QVBoxLayout*colorLayout=new QVBoxLayout(colorGroup);colorLayout-addWidget(new QRadioButton(Black and White);colorLayout-addWid
23、get(new QRadioButton(Color);groupLayout-addWidget(colorGroup);,Horizontal box,包含 group boxes,vertical boxes,radio buttons,布局管理器设计器,可以使用设计器来建立同样的结构,通用部件,Qt包含针对所有情形的大量通用部件;第三方控件,如QWT 自定义控件,尺寸(size)的策略,布局管理器是在空间和其他布局管理器之间进行协调布局管理器提供布局结构水平布局和垂直布局网格布局部件则提供各个方向上的尺寸策略最大和最小尺寸,尺寸的策略,例子未完成!,printerList-setSiz
24、ePolicy(QSizePolicy:Expanding,QSizePolicy:Fixed),尺寸的策略,每一个widget有一个大小的示意,它给出了各个方向上尺寸的策略Fixed 规定了widget的尺寸Minimum 规定了可能的最小值Maximum 规定可能的最大值Preferred 给出最好的值但不是必须的Expanding 同preferred,但希望增长MinimumExpanding 同minimum,但希望增长Ignored 忽略规定尺寸,widget得到尽量大的空间,如果?,2个 preferred 相邻1个 preferred,1个 expanding2个 expand
25、ing 相邻空间不足以放置widget(fixed),关于尺寸的更多信息,可用最大和最小属性更好地控制widget的大小maximumSize 最大可能尺寸minimumSize 最小可能尺寸,ui-pushButton-setMinimumSize(100,150);ui-pushButton-setMaximumHeight(250);,伸缩因子,控制缩放时,各控件的缩放比例。,设计器介绍,以前设计器(Designer)是一个独立的工具,但现在是QtCreator的一个组成部分可视化窗体编辑器拖放部件安排布局进行信号连接,设计器介绍,sources*.cpp,executables,obj
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Qt入门培训 Qt 入门 培训 PPT 课件
链接地址:https://www.31ppt.com/p-5625906.html