/*********************************************************************************************
* Qt Quick Hello World hacking
* 说明:
* 本代码是Qt生成Quick应用程序的时候自动生成Hello World程序;
*
* 2015-5-17 深圳 晴 南山平山村 曾剑锋
********************************************************************************************/ \\\\\\\\\-*- 目录 -*-/////////
| 一、main.cpp
| 二、main.qml
| 三、MainForm.ui.qml
\\\\\\\\\\\\\\\////////////// 一、main.cpp
#include <QApplication>
#include <QQmlApplicationEngine> int main(int argc, char *argv[])
{
/**
* The QApplication class manages the GUI application's control flow and main settings.
* 初始化并配置GUI界面环境
*/
QApplication app(argc, argv); /**
* QQmlApplicationEngine provides a convenient way to load an application from a single QML file.
* 创建QML引擎(engine)
*/
QQmlApplicationEngine engine;
/**
* QStringLiteral: Creating a QString from it is free in this case, and the generated string data
* is stored in the read-only segment of the compiled object file.
* 这是一个宏,用于创建一个字符串,该字符串存放在自读数据区
* QUrl: The most common way to use QUrl is to initialize it via the constructor by passing a QString.
* Otherwise, setUrl() can also be used.
* 最常用于初始化一个QUrl的是给其构造函数传一个字符串,此外也可以使用setUrl()
* engine.load: Loads the root QML file located at filePath:.
* 加载用QML引擎加载要显示的界面
*/
engine.load(QUrl(QStringLiteral("qrc:/main.qml"))); /**
* Enters the main event loop and waits until exit() is called.
* 进入主事件循环,并等待直到exit()函数被调用
*/
return app.exec();
} 二、main.qml
import QtQuick 2.4
import QtQuick.Controls 1.3
import QtQuick.Window 2.2
import QtQuick.Dialogs 1.2 /**
* ApplicationWindow is a Window that adds convenience for positioning items, such as MenuBar, ToolBar,
* and StatusBar in a platform independent manner.
* 被main.cpp调用,显示的主窗口
*/
ApplicationWindow {
title: qsTr("Hello World") //窗口的标题: Hello World
width: //窗口宽:640(单位不知道)
height: //窗口高:480(单位不知道)
/**
* Note: By default, an ApplicationWindow is not visible.
* 窗口设为可见
*/
visible: true /**
* 为窗口添加菜单栏,我怎么感觉应该叫菜单条 :)
*/
menuBar: MenuBar {
/**
* 观察这里,同一级别只有一个Menu,也就意味着这个菜单只有一个菜单选项
*/
Menu {
title: qsTr("&File") //唯一的一个菜单的名字叫:File。你可以通过Alt+F快捷键来操作
/**
* 观察这里,同一级别,有两个子菜单选项
*/
MenuItem {
text: qsTr("&Open") //第一个子菜单的名字是:Open。你可以通过Alt+O快捷键来操作
/**
* 1. onTriggered: 是代表点击了一次Open这个子菜单
* 2. messageDialog.show: 代表会弹出信息框
* 3. qsTr: Wherever your script uses "quoted text" for text that will be presented to the user,
* ensure that it is processed by the QCoreApplication::translate() function. Essentially
* all that is necessary to achieve this is to use the qsTr() script function.
* 意思也就是说如果你要显示字符串,就用这个函数处理一下再显示的意思
*/
onTriggered: messageDialog.show(qsTr("Open action triggered"));
}
MenuItem {
text: qsTr("E&xit") //第一个子菜单的名字是:Exit。你可以通过Alt+E快捷键来操作
onTriggered: Qt.quit(); //退出
}
}
} /**
* 这里其实是去找同一级目录下的MainForm.ui.qml文件,而MainForm.ui.qml文件中必须是一个Item类型的控件
*/
MainForm {
anchors.fill: parent //设置填充方式
/**
* 设置MainForm.ui.qml中3个按键的单击事件,弹一个信息框
*/
button1.onClicked: messageDialog.show(qsTr("Button 1 pressed"))
button2.onClicked: messageDialog.show(qsTr("Button 2 pressed"))
button3.onClicked: messageDialog.show(qsTr("Button 3 pressed"))
} MessageDialog {
id: messageDialog //消息对话框的变量名
title: qsTr("May I have your attention, please?") //信息框的标题 /**
* 我个人认为这是动态绑定一个函数,这个函数是显示函数(show)
*/
function show(caption) {
messageDialog.text = caption; //信息框显示的内容
messageDialog.open(); //让信息框显示
}
}
} 三、MainForm.ui.qml
import QtQuick 2.4
import QtQuick.Controls 1.3
import QtQuick.Layouts 1.1 /**
* All visual items in Qt Quick inherit from Item. Although an Item object has no visual appearance,
* it defines all the attributes that are common across visual items, such as x and y position,
* width and height, anchoring and key handling support.
*
* The Item type can be useful for grouping several items under a single root visual item.
* 个人感觉Item相当于是一个容器
* Rectangle items are used to fill areas with solid color or gradients, and/or to provide a rectangular border.
* 这里个人尝试了将Item换成Rectangle,没什么很大的变化,能够正常的显示,不过还是建议使用Item,因为貌似Rectangle更适合做有边框效果的事。
*/
Item {
width: //宽:640(单位未知)
height: //高:480(单位未知) /**
* Property aliases are properties which hold a reference to another property.
* 别名属性设置,并设置对应的值,主要是为了方便外部引用
*/
property alias button3: button3
property alias button2: button2
property alias button1: button1 /**
* 这里采用列布局
*/
RowLayout {
anchors.centerIn: parent //对齐方式:居中 /**
* 接下来放置3个按钮(Button)
*/
Button {
id: button1 //按钮的变量名
text: qsTr("Press Me 1") //按钮的显示文字
} Button {
id: button2
text: qsTr("Press Me 2")
} Button {
id: button3
text: qsTr("Press Me 3")
} }
}

Qt Quick Hello World hacking的更多相关文章

  1. 《Qt Quick 4小时入门》学习笔记4

    http://edu.csdn.net/course/detail/1042/14806?auto_start=1 Qt Quick 4小时入门 第七章:处理鼠标与键盘事件 1.处理鼠标事件 鼠标信号 ...

  2. 《Qt Quick 4小时入门》学习笔记3

    http://edu.csdn.net/course/detail/1042/14807?auto_start=1 Qt Quick 4小时入门 第八章:Qt Quick中的锚(anchors)布局 ...

  3. 《Qt Quick 4小时入门》学习笔记2

    http://edu.csdn.net/course/detail/1042/14805?auto_start=1   Qt Quick 4小时入门 第五章:Qt Quick基本界面元素介绍   1. ...

  4. 《Qt Quick 4小时入门》学习笔记

    http://edu.csdn.net/course/detail/1042/14804?auto_start=1   Qt Quick 4小时入门 第五章:Qt Quick里的信号与槽   QML中 ...

  5. 从头学Qt Quick(3)-- 用QML写一个简单的颜色选择器

    先看一下效果图: 实现功能:点击不同的色块可以改变文字的颜色. 实现步骤: 一.创建一个默认的Qt Quick工程: 二.添加文件Cell.qml 这一步主要是为了实现一个自定义的组件,这个组件就是我 ...

  6. 从头学Qt Quick(1) --体验快速构建动态效果界面

    自2005年Qt4发布以来,Qt已经为成千上万的应用程序提供了框架服务,现在Qt已经基本上支持所有的开发平台了,这里面既包含了桌面.嵌入式领域,也包括了Android.IOS.WP等移动操作平台,甚至 ...

  7. Qt 控制watchdog app hacking

    /************************************************************************** * Qt 控制watchdog app hack ...

  8. Qt Quick实现的涂鸦程序

    之前一直以为 Qt Quick 里 Canvas 才干够自绘.后来发觉不是,原来还有好几种方式都能够画图! 能够使用原始的 OpenGL(Qt Quick 使用 OpenGL 渲染).能够构造QSGN ...

  9. Qt Quick实现的疯狂算数游戏

    使用 Qt Quick 写了个小游戏:疯狂算数.支持 Windows 和 Android 两个平台. 游戏简单,但牵涉到下面你的 Qt Quick 主题: 自己实现一个按钮 自适应分辨率 国际化 QM ...

随机推荐

  1. ubuntu14.04, libtinyxml.so.2.6.2: cannot open shared object file: No such file or directory

    打包/opt/ros 打包项目文件install 到一台没有安装ros环境的机器上启动项目 source ros/indigo/setup.bash source install/setup.bash ...

  2. testNG 学习笔记 Day2 配置testNG自带的监听器

    IntelliJ IDEA配置testNG自带的监听器的时候,操作如下菜单栏中 run ----> 下拉菜单中的 Edit Configurations ----> 新矿口中TeatNG下 ...

  3. B2B、B2C、C2C、O2O 和 P2P 的含义

    B2C(Business-to-Customer)商家对客户 我开一家公司卖东西,你来买,即B2C.生活中常用的比如我们经常在天猫旗舰店上面购物,天猫入驻的都是商家,而我们买东西的就是客户,这就是B2 ...

  4. rsync+inotify文件同步 - 同步慢的问题

    rsync+inotify文件同步 - 同步慢的问题 我们来看网上的教程,我加了注释.(网上所有的教程基本都一模一样,尽管写法不一样,致命点都是一样的) #!/bin/bash /usr/bin/in ...

  5. WPF StoryBoard用法

    时间:2011-06-15 21:26来源:百度空间 作者:shichen4 点击: 次 StoryBoard使用,Xaml转cs代码 Canvas.Triggers EventTriggerRout ...

  6. Please, another Queries on Array? CodeForces - 1114F (线段树,欧拉函数)

    这题刚开始看成求区间$\phi$和了........先说一下区间和的做法吧...... 就是说将题目的操作2改为求$(\sum\limits_{i=l}^{r}\phi(a[i]))\%P$ 首先要知 ...

  7. python-day21--time模块

    一.三种表示方法 1.时间戳(timestamp): time.time( )       #得到的是float类型 2.格式化(Format String): time.strftime('%Y/% ...

  8. hdu多校(二) 1004 1007 1010

    Game Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  9. nyoj311(完全背包变形)

    完全背包 时间限制:3000 ms  |  内存限制:65535 KB 难度:4   描述 直接说题意,完全背包定义有N种物品和一个容量为V的背包,每种物品都有无限件可用.第i种物品的体积是c,价值是 ...

  10. ORACLE中使用DBMS_SQL获取动态SQL执行结果中的列名和值

    1.获取动态SQL中的列名及类型 DECLARE l_curid INTEGER; l_cnt NUMBER; l_desctab dbms_sql.desc_tab; l_sqltext ); BE ...