QML Reference
来源:互联网 发布:iphone7怎么关闭4g网络 编辑:程序博客网 时间:2024/05/22 00:34
工程中使用QML需要配置下面三个选项:
1、pro文件中需要 QT += qml
2、C++头文件包含include <QtQml>
3、qml文件中需要引入 import QtQml 2.0
QML 基本语法:
1、QML对象类型
(1)用户自定义QML类型。该类型写入一个单独的后缀是qml的文件中,文件名首字母大写。如: SquareButton
// SquareButton.qml
import QtQuick 2.0
Rectangle {
width: 100; height: 100
color: "red"
MouseArea {
anchors.fill: parent
onClicked: console.log("Button clicked!")
}
}
anchors.fill provides a convenient way for one item to have the same geometry as another item, and is equivalent to connecting all four directional anchors.原文是这样意思是这个图元整个geometry 和父图元相同,即填充到整个父。
//myapplication.qml
import QtQuick 2.0
SquareButton{}
终端中运行qmlscene -I import myapplication.qml,就可以看到效果了。
The root object definition in a .qml file defines the attributes that are available for a QML type.原文这样理解就是自定义的类型可以访问和修改内部的任何属性例子为证。
//myapplication.qml
import QtQuick 2.0
//SquareButton{}
Column{
spacing: 2
SquareButton{width:50;height:50}
SquareButton{x:50;color:"blue"}
SquareButton{radius:10}
}
import QtQuick 2.0
//SquareButton{}
Column{
spacing: 2
SquareButton{width:50;height:50}
SquareButton{x:50;color:"blue"}
SquareButton{radius:10}
}
import QtQuick 2.0
//SquareButton{}
Column{
spacing: 2
// SquareButton{width:50;height:50}
// SquareButton{x:50;color:"blue"}
// SquareButton{radius:10}
SquareButton{color:"red";width:50;height: 50}
SquareButton{id:greenRect;color: "green";width:20;height: 50}
SquareButton{color: "blue";width:50;height:20}
move: Transition {
NumberAnimation{properties: "x,y";duration: 1000}
}
focus: true
Keys.onSpacePressed: greenRect.visible = !greenRect.visible
}下面是对于信号槽调用,
// SquareButton.qml
import QtQuick 2.0
Rectangle {
id:root
width: 100; height: 100
color: "red"
signal buttonClick(real x,real y)
function radomsizeColor()
{
root.color = Qt.rgba(Math.random(),Math.random(),Math.random(),1)
}
MouseArea {
anchors.fill: parent
//onClicked: console.log("Button clicked!")
onClicked: root.buttonClick(mouse.x,mouse.y)
}
}
//myapplication.qml
import QtQuick 2.0
SquareButton{
onButtonClick: {
console.log("Click:",x,y)
radomsizeColor()
}
}这里有个自定义信号的知识点,注意信号定义小写字母开头,槽这边on+信号名(大写字母开头)。
import QtQuick 2.0
//SquareButton{}
Column{
spacing: 2
SquareButton{width:50;height:50}
SquareButton{x:50;color:"blue"}
SquareButton{radius:10}
}
class Message : public QObject{Q_OBJECTQ_PROPERTY(QString author READ author WRITE setAuthor NOTIFY authorChange)Q_PROPERTY(QDate authorDate READ authorDate WRITE setAuthorDate NOTIFY dateChange)
qmlRegisterType<Message>("MessagePerson",1,0,"Message");
import MessagePerson 1.0 Message{ author:"王bull"authorDate:new Date()}
- QML Reference
- QML官方系列教程——The QML Reference
- QML视图元素 Visual Elements In QML Qt 5.6.0 Reference Documentation
- qml
- QML
- QML
- qml
- QML
- QML
- qml
- QML
- QML
- Reference
- reference
- Reference
- Reference
- reference
- reference
- QTP之轻松写入html log
- QTP测试之With秒用
- QTP之Description秒用
- QTP之IE最大化
- appcan.windw.open appcan.frame.open appcan.window.openPopOver evaluateScript
- QML Reference
- cocos2d-x win32程序 按键监听
- 长尾理论
- 【leetcode】【单链表】【24】Swap Nodes in Pairs
- 当前已禁用此服务的元数据发布
- vs2010 vc++ 写成dll 被易语言dll 调用然后返回文本
- 将现有jar打包成一个大的jar
- Swift学习之一: ? 和 ! 详解
- Representive learning: A review and New respective