-
2020-08-18 10:53:18
最近学习QML,中间遇到了一些问题,难免要翻阅一些资料,当查看到官方文档时候,我的小脑袋,有点扛不住了,全是英文,所以这里我打算把我看到的,学习过程中接触到的文档都翻译成中文,有些是机翻,有些是人为。当你如果在阅读我的文章时候发现哪里有不通顺的,可以查看官方地址。如果你的英文阅读水平很厉害,也可以直接阅读英文文档,下面附上官方入口。
QML官方文档入口:https://doc.qt.io/qt-5/qmlreference.html
索引(持续更新...建议收藏)
- QML语法基础知识(QML Syntax Basics)
- QML对象属性(QML Object Attributes)
- ID属性(The id Attribute)
- Property属性(Property Attributes)
- 定义Property属性(Defining Property Attributes)
- 自定义属性定义中的有效类型(Valid Types in Custom Property Definitions)
- Property属性赋值(Assigning Values to Property Attributes)
- 静态值和绑定表达式值(Static Values and Binding Expression Values)
- 类型安全(Type Safety)
- 特殊的property属性类型(Special Property Types)
- 分组属性(Grouped Properties)
- 属性别名(Property Aliases)
- 属性别名的注意事项(Considerations for Property Aliases)
- 属性别名和类型(Property Aliases and Types)
- 默认属性(Default Properties)
- 必需的属性(Required Properties)
- 只读属性(Read-Only Properties)
- 属性修改器对象(Property Modifier Objects)
- 信号的属性(Signal Attributes)
- 信号处理程序属性(Signal Handler Attributes)
- 方法属性(Method Attributes)
- 附加属性和附加信号处理程序(Attached Properties and Attached Signal Handlers)
- 枚举属性(Enumeration Attributes)
- QML属性绑定(Property Binding)
- QML信号和处理程序事件系统(Signal and Handler Event System)
- 集成QML和JavaScript(Integrating QML and JavaScript)
- QML类型系统(The QML Type System)
- QML模块(QML Modules)
- QML文件(QML Documents)
更多相关内容 -
qml中文手册pdf
2017-12-28 23:35:17qml中文手册pdf,全中文,很详细。各种示例,简单易学。 -
Qt--QML中文手册
2018-03-31 16:17:04中文学习手册,从最基本的,到网络应用全部涉及到,很全面的! -
QML中文文档,QML中文手册,QML入门手册
2018-12-28 20:49:02 -
QML中文版,内容非常详细.rar
2021-06-28 10:42:07QML中文版文档,供各位学客下载。 -
QML 参考手册
2015-09-11 16:30:38内含英文原版和中文翻译以及源代码 英文名为Qt5 cadaques QML 开发参考手册 中文翻译 -
QT--QML中文教程.pdf
2021-01-27 15:23:01详细的QML中文教程 -
qmlbook:即将出版的qml书的源代码-Source code
2021-03-25 02:05:08QmlBook项目 这是QML书籍内容的源代码( )。 它是根据知识共享署名-非商业性共享方式4.0许可获得许可的。 我们希望您喜欢它,希望它能帮助您学习Qt5。 这些代码示例已获得BSD许可。 图书许可证: : 源代码示例... -
QtQuick中文手册PDF版
2019-07-22 20:36:44资源名称:Qt Quick中文手册 PDF版内容简介:本文档主要讲述的是Qt Quick中文手册;Qt Quick 提供了一套高动态,丰富的 QML 元素来定制用户界面的说明性框架。Qt Quick 有助于程序开发员与界面设计员的合作为便携式... -
QT 中文手册
2017-11-14 19:19:35学习图形界面开发,肯定离不开帮助文档的使用,因为它不像 C 语言那样就那么几个函数接口,图形接口的接口可以用海量来形容,常用的我们可能能记住,其它的真的没有必要去记,用到什么就去帮助文档查看用法。 -
qmlbook实例源码(全).rar
2020-05-01 21:39:46qmlbook 源码各章 全部示例源码, ch01-meetqt-assets.tgz │ ch04-qmlstart-assets.tgz │ ch05-fluid-assets.tgz │ ch06-controls-assets.tgz │ ch07-modelview-assets.tgz │ ch08-canvas-assets.tgz │ ch09-... -
QMLBook(中文版)
2018-04-18 11:37:39QMLBook(中文版),qt5的入门介绍pdf文档,着重介绍qml部分 QMLBook(中文版),qt5的入门介绍pdf文档,着重介绍qml部分 QMLBook(中文版),qt5的入门介绍pdf文档,着重介绍qml部分 -
QmlBook 学习中文Pdf版
2018-07-03 14:16:00适合Qml初学者,简单入门,能快速了解Qml,方便以后的学习 -
QmlBook中文2020-8-28.rar
2020-08-28 16:24:00最近需要看下qml手册,搜了下资源都是需要很多的积分,开源的东西,何必呢。在官网找了份,下载下来,共享给大家,需要的自取。一个积分,意思下。 -
QmlBook-In-Chinese-master.zip
2021-08-26 20:07:27QML学习资源 -
qml book 中文版
2017-12-01 09:20:07qml 中文技术指导文档qml 参考手册 qml 中文技术指导文档qml 参考手册 -
QML入门教程(12): Item介绍
2021-03-21 19:08:33Item的定义 Qt助手的解释 The Item type is the base type for all visual items in Qt Quick. All visual items in Qt Quick inherit from Item. Although an Item object has no visual appearance, it defines ...Item的定义
Qt助手的解释
The Item type is the base type for all visual items in Qt Quick.
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
根据Qt官方解释可知,Item是Qt Quick中所有可视项目的基类,就像QWidget是Qt所有控件的父类。
Qt Quick中的所有可视化项目都继承自Item,尽管Item对象没有可视外观,但它定义了可视项中常见的所有属性,如x和y位置、宽度和高度、anchor和键处理支持。
Item的属性
下面的是Item的属性,其它控件也都有这些属性
Properties
-
activeFocus : bool
-
activeFocusOnTab : bool
-
- anchors.top : AnchorLine
- anchors.bottom : AnchorLine
- anchors.left : AnchorLine
- anchors.right : AnchorLine
- anchors.horizontalCenter : AnchorLine
- anchors.verticalCenter : AnchorLine
- anchors.baseline : AnchorLine
- anchors.fill : Item
- anchors.centerIn : Item
- anchors.margins : real
- anchors.topMargin : real
- anchors.bottomMargin : real
- anchors.leftMargin : real
- anchors.rightMargin : real
- anchors.horizontalCenterOffset : real
- anchors.verticalCenterOffset : real
- anchors.baselineOffset : real
- anchors.alignWhenCentered : bool
-
antialiasing : bool
-
baselineOffset : int
-
children : list
-
- childrenRect.x : real
- childrenRect.y : real
- childrenRect.width : real
- childrenRect.height : real
-
clip : bool
-
containmentMask : QObject*
-
data : list
-
enabled : bool
-
focus : bool
-
height : real
-
implicitHeight : real
-
implicitWidth : real
-
layer.effect : Component
-
layer.enabled : bool
-
layer.format : enumeration
-
layer.mipmap : bool
-
layer.samplerName : string
-
layer.samples : enumeration
-
layer.smooth : bool
-
layer.sourceRect : rect
-
layer.textureMirroring : enumeration
-
layer.textureSize : size
-
layer.wrapMode : enumeration
-
opacity : real
-
parent : Item
-
resources : list
-
rotation : real
-
scale : real
-
smooth : bool
-
state : string
-
states : list
-
transform : list
-
transformOrigin : enumeration
-
transitions : list
-
visible : bool
-
visibleChildren : list
-
width : real
-
x : real
-
y : real
-
z : real
下面介绍几个陌生的属性
(1)z 设置图元顺序
Qt助手的解释如下:
设置兄弟项的堆叠顺序。默认情况下,堆叠顺序为0。
具有较高堆叠值的项被绘制在具有较低堆叠顺序的兄弟项上。具有相同堆叠值的项目将按照它们出现的顺序从下往上绘制。具有负叠加值的项被绘制在其父元素的内容下。
例如下面的代码
import QtQuick 2.12 import QtQuick.Window 2.12 Window { visible: true width: 640 height: 480 title: qsTr("Hello World") Item { Rectangle { color: "red" width: 100; height: 100 } Rectangle { color: "blue" x: 50; y: 50; width: 100; height: 100 } } }
默认是按照代码顺序,先写的矩形在下方,后写的在下方,如下图:
如果设置z属性值,那么,就可以手动设置图元的叠加顺序
Item { Rectangle { color: "red" width: 100; height: 100 z:0.5 } Rectangle { color: "blue" x: 50; y: 50; width: 100; height: 100 } }
如下图,此时红色矩形的叠加在蓝色矩形上面
opacity是透明度,合理的设置z和opacity属性值,可以做到意想不到的效果。
(2)focus
是否获得焦点, 默认是false. 在处理窗口键盘事件时,需要将该属性设为true,例如下面的代码是键盘事件的处理:
import QtQuick 2.12 import QtQuick.Window 2.12 Window { visible: true width: 640 height: 480 title: qsTr("Hello World") Rectangle { width: parent.width; height: parent.height; color: "#c0c0c0"; focus: true; Keys.enabled: true; Keys.onEscapePressed: Qt.quit(); Keys.onBackPressed: Qt.quit(); Keys.onPressed: { switch(event.key){ case Qt.Key_0: case Qt.Key_1: case Qt.Key_2: case Qt.Key_3: case Qt.Key_4: case Qt.Key_5: case Qt.Key_6: case Qt.Key_7: case Qt.Key_8: case Qt.Key_9: keyView.text = event.key - Qt.Key_0; break; } } Text { id: keyView; font.bold: true; font.pixelSize: 24; text: qsTr("text"); anchors.centerIn: parent; } } }
因为Item自己是不可见的,我们需要添加到窗口Window中, 把整个Rectangle设置窗口一样大,在Rectangle中处理键盘事件,比如按下esc或backspace就退出窗口,按下数字就在text显示出来。
其它属性可以在开发时对照Qt文档学习。
-
-
qml杂记 Qt_Quick中文手册.pdf
2011-11-16 14:13:22qml语言使用资料,以qt自带例子,讲述qml用法 -
QtQuick中文手册
2018-04-17 15:29:50QtQuick的中文帮助文档,共75页,清晰明了,帮助用户开发QML程序 -
qmlbook学习总结
2021-11-22 01:39:20这是土盐的第183篇原创文章1大家好,我是土盐。今天把qmlbook的案例代码跑了一遍,感觉还是很酸爽的。文章写完,发现代码默认排版不舒服。于是去如下网站,http://md.acli...这是 土盐 的第183篇原创文章
1
大家好,我是土盐。
今天把qmlbook的案例代码跑了一遍,感觉还是很酸爽的。
文章写完,发现代码默认排版不舒服。
于是去如下网站,http://md.aclickall.com/
美化代码排版后,复制回公众号编辑器。
无用的win下python虚拟机环境搭建。
git clone https://github.com/qmlbook/qmlbook.git cd C:\\Users\\pgjgg\\Desktop\\qml_learn\\qmlbook pip install -i https://pypi.doubanio.com/simple/ virtualenv virtualenv -p python3 qmlbook_env ./qmlbook_env/Scripts/activate.bat pip install -i https://pypi.doubanio.com/simple/ -r requirements.txt pip install -i https://pypi.doubanio.com/simple/ python-language-server 参考链接: https://github.com/qmlbook/qmlbook windows下python虚拟环境virtualenv安装和使用 - 倥偬时光 - 博客园 (cnblogs.com) https://www.cnblogs.com/cwp-bg/p/python.html python三大神器之virtualenv - 似是故人来~ - 博客园 (cnblogs.com) https://www.cnblogs.com/freely/p/8022923.html
qml+python代码运行效果,cpu内存占用动态显示:
代码位置:C:\Users\pgjgg\Desktop\qml_learn\qmlbook\docs\ch20-python\src\model
直接运行依赖项安装出错的情况下,进行了如下错误示范:
pip install -r requirements.txt
pip install Pygments-2.10.0-py3-none-any.whl pip install requests pip install pytz-2021.3-py2.py3-none-any.whl pip install Babel-2.9.1-py2.py3-none-any.whl pip install sphinxcontrib-jsmath pip install docutils-0.18-py2.py3-none-any.whl pip install sphinxcontrib_serializinghtml-1.1.5-py2.py3-none-any.whl pip install imagesize-1.3.0-py2.py3-none-any.whl pip install sphinxcontrib_applehelp-1.0.2-py2.py3-none-any.whl pip install sphinxcontrib_devhelp-1.0.2-py2.py3-none-any.whl pip install MarkupSafe pip install Jinja2-3.0.3-py3-none-any.whl pip install colorama pip install alabaster-0.7.12-py2.py3-none-any.whl pip install snowballstemmer-2.2.0-py2.py3-none-any.whl pip install sphinxcontrib-htmlhelp pip install sphinxcontrib_qthelp-1.0.3-py2.py3-none-any.whl pip install Sphinx-4.3.0-py3-none-any.whl
2
视频制作尝试,动画效果测试:
代码位置:C:\Users\pgjgg\Desktop\qml_learn\qmlbook-master\docs\ch05-fluid\src\EasingCurves
测试的是如下蓝色字体参数,在足球到最高点后的下落段的移动特效。
代码位置:C:\Users\pgjgg\Desktop\qml_learn\qmlbook\docs\ch05-fluid\src\animation\BouncingBallExample.qml
3
还有很多亮点,直接亮代码吧。
三种动画类型。
1:直接运动。
2:全过程可交互运动。
3:部分过程可交互运动。
代码位置:C:\Users\pgjgg\Desktop\qml_learn\qmlbook\docs\ch05-fluid\src\animation\AnimationTypesExample.qml
//M1>> ClickableImageV2 { id: greenBox x: 40; y: root.height-height source: "assets/box_green.png" text: "animation on property" NumberAnimation on y { to: 40; duration: 4000 } } //<<M1 //M2>> ClickableImageV2 { id: blueBox x: (root.width-width)/2; y: root.height-height source: "assets/box_blue.png" text: "behavior on property" Behavior on y { NumberAnimation { duration: 4000 } } onClicked: y = 40 // random y on each click // onClicked: y = 40+Math.random()*(205-40) } //<<M2 //M3>> ClickableImageV2 { id: redBox x: root.width-width-40; y: root.height-height source: "assets/box_red.png" onClicked: anim.start() // onClicked: anim.restart() text: "standalone animation" NumberAnimation { id: anim target: redBox properties: "y" to: 40 duration: 4000 } } //<<M3
序列化和反序列化,基于xml创建和销毁多个实例对象。
代码位置:C:\Users\pgjgg\Desktop\qml_learn\qmlbook\docs\ch15-dynamicqml\src\dynamic-scene\main.qml
import QtQuick.XmlListModel 2.0 // M1>> import QtQuick 2.5 import "create-object.js" as CreateObject Item { id: root ListModel { id: objectsModel } function addUfo() { CreateObject.create("ufo.qml", root, itemAdded); } function addRocket() { CreateObject.create("rocket.qml", root, itemAdded); } function itemAdded(obj, source) { objectsModel.append({"obj": obj, "source": source}) } // <<M1 width: 1024 height: 600 // M2>> function clearItems() { while(objectsModel.count > 0) { objectsModel.get(0).obj.destroy(); objectsModel.remove(0); } } // <<M2 // M3>> function serialize() { var res = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<scene>\n"; for(var ii=0; ii < objectsModel.count; ++ii) { var i = objectsModel.get(ii); res += " <item>\n <source>" + i.source + "</source>\n <x>" + i.obj.x + "</x>\n <y>" + i.obj.y + "</y>\n </item>\n" } res += "</scene>"; return res; } // <<M3 // M4>> XmlListModel { id: xmlModel query: "/scene/item" XmlRole { name: "source"; query: "source/string()" } XmlRole { name: "x"; query: "x/string()" } XmlRole { name: "y"; query: "y/string()" } } function deserialize() { dsIndex = 0; CreateObject.create(xmlModel.get(dsIndex).source, root, dsItemAdded); } function dsItemAdded(obj, source) { itemAdded(obj, source); obj.x = xmlModel.get(dsIndex).x; obj.y = xmlModel.get(dsIndex).y; dsIndex ++; if (dsIndex < xmlModel.count) CreateObject.create(xmlModel.get(dsIndex).source, root, dsItemAdded); } property int dsIndex // <<M4 Column { anchors.left: parent.left anchors.top: parent.top anchors.topMargin: 10 spacing: 10 width: 100 Image { anchors.horizontalCenter: parent.horizontalCenter source: "ufo.png" MouseArea { anchors.fill: parent onClicked: addUfo(); } } Image { anchors.horizontalCenter: parent.horizontalCenter source: "rocket.png" MouseArea { anchors.fill: parent onClicked: addRocket(); } } Rectangle { anchors.horizontalCenter: parent.horizontalCenter width: 100 height: 40 color: "#53d769" MouseArea { anchors.fill: parent onClicked: { xmlModel.xml = serialize(); clearItems(); } } } Rectangle { anchors.horizontalCenter: parent.horizontalCenter width: 100 height: 40 color: "#fed958" MouseArea { anchors.fill: parent onClicked: deserialize(); } } } }
4
图片阅读器:
代码位置:C:\Users\pgjgg\Desktop\qml_learn\qmlbook\docs\ch06-controls\src\imageviewer-desktop
Image { id: image anchors.fill: parent fillMode: Image.PreserveAspectFit asynchronous: true } FileDialog { id: fileOpenDialog // ... title: "Select an image file" folder: shortcuts.documents nameFilters: [ "Image files (*.png *.jpeg *.jpg)" ] onAccepted: image.source = fileOpenDialog.fileUrl; }
画笔画布工具:
代码位置:C:\Users\pgjgg\Desktop\qml_learn\qmlbook\docs\ch09-canvas\src\canvas\paint.qml
// M1>> Row { id: colorTools anchors { horizontalCenter: parent.horizontalCenter top: parent.top topMargin: 8 } property variant activeSquare: red property color paintColor: "#33B5E5" spacing: 4 Repeater { model: ["#33B5E5", "#99CC00", "#FFBB33", "#FF4444"] ColorSquare { id: red color: modelData active: parent.paintColor == color onClicked: { parent.paintColor = color } } } } // <<M1 Rectangle { anchors.fill: canvas border.color: "#666666" border.width: 4 } // M2>> Canvas { id: canvas anchors { left: parent.left right: parent.right top: colorTools.bottom bottom: parent.bottom margins: 8 } property real lastX property real lastY property color color: colorTools.paintColor onPaint: { var ctx = getContext('2d') ctx.lineWidth = 1.5 ctx.strokeStyle = canvas.color ctx.beginPath() ctx.moveTo(lastX, lastY) lastX = area.mouseX lastY = area.mouseY ctx.lineTo(lastX, lastY) ctx.stroke() } MouseArea { id: area anchors.fill: parent onPressed: { canvas.lastX = mouseX canvas.lastY = mouseY } onPositionChanged: { canvas.requestPaint() } } } // <<M2
qmlbook书籍代码和运行环境分享 链接:https://pan.baidu.com/s/1Bt1vRkjfazQTnLfoTXgzlQ 提取码:5514
今天又是秃头的一天,卒。
--End--
-
QML内部培训资料(中文高清版)
2013-02-16 21:28:54权威的QML编程指南,完整的知识体系介绍,内有丰富的代码示例和图示说明,QML参考手册。 -
Qt QML 与 C++ 交互 信号与槽 属性 注册等初学者手册
2019-08-02 20:48:53QML 是一套 QT 开发前端显示的软件,其最大特色就是基于 Qt 的宏系统实现了与 C++ 及 Javascript 交互和连接,本篇主要讲解 QML 与 C++ 的交互( QML 调用 C++),至于 C++ 调用 QML 部分相对比较简单查看官方... -
《QmlBook》笔记(14):粒子系统示例
2021-10-27 16:54:36*/ } // ItemParticle //粒子项 粒子项可以将QML元素项作为粒子发射 // { // system: particles // delegate: Rectangle // { // id: rect // width: 10 // height: 10 // color: "red" // radius: 10 // } // } //... -
《QmlBook》笔记(7):动画示例
2021-10-04 09:54:46例1:同时设置多个属性动画 import QtQuick 2.9 import QtQuick.Window 2.2 Window { id:win visible: true width: img_bg.width height: img_bg.height Image { id:img_bg; source: "qrc:/img/... { -
Qt 中文手册
2021-01-15 13:55:34Qt Creator手册 Qt入门 如果您以前没有使用过集成开发环境(IDE),或者想知道Qt Creater是一个什么样的IDE,转至 IDE概述。 如果您以前没有使用过Qt Creator,并且希望熟悉用户界面的各个部分,转至 用户... -
Qt_Quick中文手册
2012-12-23 20:32:02Qt Quick提供了一套高动态,丰富的QML元素来定制用户界面的说明性框架。Qt Quick有助于程序开发员与界面设计员的合作为便携式设备建立流畅的用户界面。 -
QT中文帮助文档.chm.zip
2019-06-19 16:20:08qt帮助文档,对于不熟悉qt api的同学提供帮助。包括简单的qt上手教程。 -
QML Book技术文档
2019-10-02 23:15:33认识QML 开始学习 QML快速入门 基本元素 布局 输入组件 动态元素 模型-视图-代理 画布元素 粒子模型 着色器效果 多媒体 网络 存储 动态QML 认识QML 首先,以可以旋转的风车作为例子 首先,... -
PySide2学习总结(七)Qml教程
2019-01-25 21:48:22首先由一个简单的示例来进行QML的基础介绍。 在view.qml编辑代码如下: // 导入Qt附带的内置QML类型(如Rectangle,Image,...) import QtQuick 2.0 // 使用Rectangle类型声明根元素,Rectangle类型是在QML中创建... -
QT安装QML环境配置与QML学习指南
2017-02-17 15:53:00QT安装 QML环境配置 QML学习指南