QML学习文档 - huangchunquanmaker的日志 - 网易博客 太详细全面了,很好很强大【z】

欢迎加入我们的QQ群,无论你是否工作,学生,只要有c / vc / c++ 编程经验,就来吧!158427611 

欢迎加入我们的QQ群,无论你是否工作,学生,只要有c / vc / c++ 编程经验,就来吧!158427611

1. 介绍

QML是一种描述语言,主要是对界面效果等的一种描述,它可以结合javaScript来进行更复杂的效果及逻辑实现。比如做个游戏,实现一些更有趣的功能等


}

代码是绘制一个蓝色的矩形,宽 200 高 200, import包含一个qt4.7的包

3.基本元素的介绍(自己翻译意思会有出入,敬请见谅)

Item 基本的项元素 在QML中所有可视化的向都继承他

Rectangle 基本的可视化矩形元素

Gradient 定义一个两种颜色的渐变过程

GradientStop 定义个颜色,被Gradient使用

BorderImage(特殊的项) 定义一张图片并当做边界

AnimatedImage 为播放动画存储一系列的帧

TextInput 显示可编辑为文本

RegExpValidator 验证字符串正则表达式

TextEdit 显示多行可编辑文本

基本的交互项

Flickable 提供一种浏览整张图片的一部分的效果,具体看例子

Flipable 提供一个平面,可以进行翻转看他的前面或后面,具体看例子

状态

State 定义一个配置对象和属性的集合

PropertyChanges 使用一个State描述属性的改变

StateGroup 包含一个状态集合和状态变换

ParentChange 重新定义父集,也就是换个父节点

AnchorChanges 在一个状态中改变anchors

动画和变换

Behavior 默认的属性变换动画

SequentialAnimation 对定义的动画串行播放

ParallelAnimation 对定义的动画并行播放

PropertyAnimation 属性变换动画

NumberAnimation 对实数类型属性进行的动画

工作中的数据

Binding 在创建的时候绑定一些数据到一些属性

ListElement 定义ListModel的一个数据项

VisualItemModel 包含可视化项(visual items)到一个view中,相当是一个容器

VisualDataModel 包含一个model和一个delegate,model包含需要的数据,delegate设计显示的项的信息,具体的去看例子

Package 他的目的是把VisualDataModel共享给多个view,具体还要学习

XmlListModel 特殊的一个模式使用XPath表达式,使用xml来设置元素,参考例子

XmlRole XmlListModel的一个特殊的角色

试图

ListView 提供一个链表显示模型试图

GridView 提供一个网格显示模型试图

PathView 提供一个内容沿着路径来显示的模型

Path 定义一个PathView使用的轨迹

PathLine 定义一个线性的轨迹

PathQuad 定义一个二次贝塞尔曲线的轨迹

PathCubic 定义一个三次贝塞尔曲线的轨迹

定位器

实用

变换



}

位置是:0,0宽高分别是200,颜色是红色

}

GradientStop { ; color: "yellow" }

GradientStop { ; color: "green" }

}

}

当图片进行缩放的时候

D.5 将根据属性horzontalTileMode 和 verticalTileMode 进行缩放

border { left: 30; top: 30; right: 30; bottom: 30 }

}


width: animation.width; height: animation.height + 8

AnimatedImage { id: animation; source: "animation.gif" }

x: (animation.width - width) * animation.currentFrame / frames

}

}

}

}

IntValidator{id: intval; bottom: 10; top: 100;}

}

DoubleValidator{id: intval; decimals: 4; bottom: 10; top: 100; notation: DoubleValidator.StandardNotation}

}

表示 开始位置必须是一个大写或小写字母

RegExpValidator{id: intval; regExp:/^[a-zA-Z]{1}[0-1]{0,2}[a-z]{1,3}$/;}

}


text: "<b>Hello</b> <i>World!</i>"

}


主要是用来判断鼠标事件的区域

}



显示一个200x200的框,框中显示图片上200x200的部分

contentWidth: image.width; contentHeight: image.height

Image { id: image; source: "../Images/need.png" }

}


包含两个面,一个前面,一个后面,实现一个控件前后的翻转效果,并且在后面可以添加一些控制


origin.x: flipable.width/2; origin.y: flipable.height/2

axis.x: 0; axis.y: 1; axis.z: 0 // rotate around y-axis

PropertyChanges { target: flipable; angle: 180 }

NumberAnimation { properties: "angle"; duration: 1000 }

onClicked: flipable.flipped = !flipable.flipped

}





onClicked: myRect.state == 'clicked' ? myRect.state = "" : myRect.state = 'clicked';

PropertyChanges { target: myRect; color: "red" }

}




MouseArea { anchors.fill: parent; onClicked: myText.state = 'myState' }

}








在状态中可以对脚本中的函数进行调用

// Sc.js

{

return "blue";

}


// test.qml

}




ParentChange { target: blueRect; parent: redRect; x: 10; y: 10 }

MouseArea { anchors.fill: parent; onClicked: blueRect.state = "reparented" }

}




Rectangle { id: myRect; width: 50; height: 50; color: "red" }

MouseArea { anchors.fill: parent; onClicked: window.state = "reanchored" }

}




}


串行播放多个动画

NumberAnimation {target:rect; properties:"x"; to: 50; duration: 1000 }

NumberAnimation {target:rect; properties:"y"; to: 50; duration: 1000 }

}




NumberAnimation {target:rect; properties:"x"; to: 50; duration: 1000 }

NumberAnimation {target:rect; properties:"y"; to: 50; duration: 1000 }

}




PropertyAnimation { properties: "x,y"; easing.type: Easing.InOutQuad }

}




NumberAnimation on x { to: 50; duration: 1000 }

}







颜色的过度

ColorAnimation on color { to: "yellow"; duration: 1000 }

}




width: 150; height: 100; anchors.centerIn: parent

name: "rotated"; PropertyChanges { target: rect; rotation: 180 }

RotationAnimation { duration: 1000; direction: RotationAnimation.Counterclockwise }

MouseArea { anchors.fill: parent; onClicked: rect.state = "rotated" }

}




ParentChange { target: blueRect; parent: redRect; x: 10; y: 10 }

NumberAnimation { properties: "x,y"; duration: 1000 }

MouseArea { anchors.fill: parent; onClicked: blueRect.state = "reparented" }

}



AnchorChanges { target: myRect; anchors.right: container.right }

// smoothly reanchor myRect and move into new position

Component.onCompleted: container.state = "reanchored"

}



延迟效果

NumberAnimation {target: myRect;to: 50; duration: 1000; properties: "x"; }

NumberAnimation {target: myRect; to: 50; duration: 1000; properties: "y"; }

}




平滑过度

Behavior on x { SmoothedAnimation { velocity: 200 } }

Behavior on y { SmoothedAnimation { velocity: 200 } }

}




平滑的过度过程,在动画结束的时候有种弹性的效果


Behavior on x { SpringAnimation { spring: 2; damping: 0.2 } }

Behavior on y { SpringAnimation { spring: 2; damping: 0.2 } }

}




主要是在动画过程中直接的改变一个属性

PropertyAction { target: theImage; property: "smooth"; value: true }

}



在动画过程中嵌入脚本的调用

}




PropertyChanges { target: rect; x: 50; y: 50 }

NumberAnimation { properties: "x,y"; easing.type: Easing.InOutQuad }

}




TextEdit { id: myTextField; text: "Please type here..." }

Binding { target: app; property: "enteredText"; value: myTextField.text }




直接看效果

}





把可视化图元添加到链表试图

Rectangle { height: 30; width: 80; color: "red" }

Rectangle { height: 30; width: 80; color: "green" }

Rectangle { height: 30; width: 80; color: "blue" }

}




看下面效果

}




具体请参考

declarative/modelviews/package










看效果

}





看例子


PathQuad { x: 120; y: 25; controlX: 260; controlY: 75 }

PathQuad { x: 120; y: 100; controlX: -20; controlY: 75 }

}





具体的看运行的例子


}






还要看



可以直接针对一些属性进行改变

PathQuad { x: 120; y: 25; controlX: 260; controlY: 75 }

PathQuad { x: 120; y: 100; controlX: -20; controlY: 75 }

}






}



横向排列

Rectangle { color: "red"; width: 50; height: 50 }

Rectangle { color: "green"; width: 20; height: 50 }

Rectangle { color: "blue"; width: 50; height: 20 }

}




Rectangle { color: "red"; width: 50; height: 50 }

Rectangle { color: "green"; width: 20; height: 50 }

Rectangle { color: "blue"; width: 50; height: 20 }

}




Rectangle { color: "red"; width: 50; height: 50 }

Rectangle { color: "green"; width: 20; height: 50 }

Rectangle { color: "blue"; width: 50; height: 20 }

Rectangle { color: "cyan"; width: 50; height: 50 }

Rectangle { color: "magenta"; width: 10; height: 10 }

}



Rectangle { color: "red"; width: 50; height: 50 }

Rectangle { color: "green"; width: 20; height: 50 }

Rectangle { color: "blue"; width: 50; height: 20 }

Rectangle { color: "cyan"; width: 50; height: 50 }

Rectangle { color: "magenta"; width: 10; height: 10 }

}



Multiple connections to the same signal are required

有多个连接要连接到相同的信号时

Creating connections outside the scope of the signal sender

创建的连接在范围之外

Connecting to targets not defined in QML


}





}




onTriggered: time.text = Date().toString() // 使用javascript获取系统时间

}






view.setSource(QUrl::fromLocalFile("MyRect.qml"));

QDeclarativeItem *item = view.rootObject()->findChild<QDeclarativeItem*>("myRect");

item->setProperty("color", QColor(Qt::yellow));








使用它可以把操作放到一个新的线程中,使得它在后台运行而不影响主GUI

具体可以看QML中它的文档






他可以创建很多相似的组件,QML中还有几个例子


}



具体看效果和文档

SystemPalette { id: myPalette; colorGroup: SystemPalette.Active }

}





载入一种字体,可以是网络上的,也可以是本地的

FontLoader { id: fixedFont; name: "Courier" }

Text { text: "Fixed-size font"; font.family: fixedFont.name }

Text { text: "Fancy font"; font.family: webFont.name }

}



不清楚



对缩放的控制

transform: Scale { origin.x: 10; origin.y: 10; xScale: 3}

}



transform: Rotation { origin.x: 25; origin.y: 25; angle: 45}

}




}



---------------------------------------------------

有一部分是还没有完成的东西,因此官方还没有提供文档


相关文章

页脚

网易公司版权所有 ©1997-2011




引文来源  QML学习文档 - huangchunquanmaker的日志 - 网易博客

欢迎加入我们的QQ群,无论你是否工作,学生,只要有c / vc / c++ 编程经验,就来吧!158427611 

欢迎加入我们的QQ群,无论你是否工作,学生,只要有c / vc / c++ 编程经验,就来吧!158427611

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: QML-QianWindow-V1版本界面是一款用户界面设计程序,它为开发人员提供了大量可自定义的UI组件,使得开发者可以轻松地创建美观、直观且易于使用的界面QML-QianWindow-V1版本界面具有界面美观,易用性强以及可扩展性强的特点。该程序提供了多种UI组件如窗口、按钮、文本框、下拉框、进度条等等。每个组件都可以基于开发需求进行个性化设计,提高了程序的可读性和可维护性。 QML-QianWindow-V1版本界面的窗口设计功能令人称赞。用户可以定制窗口的样式、位置和大小等属性,使其符合自己的需求。同时,该程序支持类似IOS与Android风格的Tab、Panel、Dialog等视图控件,让应用的界面具丰富性和交互性,提升用户体验。 此外,QML-QianWindow-V1版本界面可让用户通过实用的数据模型,快速地创建和管理表格和列表,包括多行、多列的表格和单选或多选列表,使得用户可以方便地处理大量数据。 总之,QML-QianWindow-V1版本界面通过提供易用性和可扩展性强的UI组件来简化界面设计过程,使得开发人员可以迅速开发出优秀的桌面应用程序界面,以满足用户高品质的界面需求。 ### 回答2: QML-Qianwindow-v1版本是一款基于QML语言开发的桌面应用程序,其主要特点是界面设计美观、简单易用,适用于多种应用场景。 该软件的主界面包含五个主要区域:侧边栏、消息中心、主视图、小部件和设置菜单。 侧边栏主要用于导航,其中包含主要的应用程序和功能,使用户可以轻松地进入不同的模块。 消息中心用于显示来自其他应用程序的通知,例如电子邮件或要完成的任务。 主视图是QML-Qianwindow-v1的核心区域,其中包含常见的功能和工具,例如打开的文件、书签和搜索栏。 小部件区域用于显示用户选择的小部件,例如天气预报和日历。 设置菜单区域包含应用程序的设置菜单,用户可以在此处改应用程序的选项、主题和常规设置。 总体来说,QML-Qianwindow-v1版本的界面设计非常简洁,用户友好,易于使用。它增强了用户的生产力和效率,为用户提供了一种令人愉悦的使用体验。 ### 回答3: QML-QianWindow-v1是一种基于Qt QML开发的简单易用的窗口界面库。其设计风格简洁明了,适用于各种桌面应用开发。 该库主要由三个部分组成:Title Bar、Main Body和Sidebar。其中,Title Bar是窗口的标题栏,可以自定义标题、图标、按钮、菜单等。Main Body是页面的主体内容,可以显示各种控件、窗口和布局。Sidebar是侧边栏,可以显示常用的菜单、工具、快捷方式等。 在QML-QianWindow-v1中,可以使用QianWindow来创建窗口。QianWindow提供了常用的窗口操作方法,例如最小化、最大化、关闭等。同时,该库还提供了很多常用的QML组件,例如按钮、文本框、下拉框、列表框等,这些组件可以方便快捷地进行页面设计。此外,在QML-QianWindow-v1中还支持自定义样式,可以根据需要修改组件的颜色、形状、大小等。 QML-QianWindow-v1的界面设计风格简洁明了,同时具有一定的美观度。尤其是Title Bar部分的设计非常灵活,可以根据需要自由定制。Main Body部分支持多种布局方式,可以满足不同页面设计的需求。Sidebar部分则提供了丰富的快捷操作方式,提高了用户的使用效率。 总的来说,QML-QianWindow-v1是一款非常实用的界面库,可以方便快捷地进行桌面应用开发。无论是初学者还是有经验的开发者,都可以轻松使用该库进行界面设计。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值