For faster navigation, this Iframe is preloading the Wikiwand page for QML.

QML

此條目包含指南或教學內容。 (2016年5月25日)請藉由移除或重寫指南段落來改善條目,或在討論頁提出討論。
此条目形似評論,須要清理。 (2016年5月25日)請幫助改进條目以使其語氣中立,且符合维基百科的品質標準
QML
编程范型編程範型宣告式編程脚本语言
實作者Qt發展框架
发行时间2009
当前版本
編輯維基數據鏈接
型態系統動態強型別
網站[1]
啟發語言
JavaScriptQt
影響語言
Qt
QML
扩展名
.qml
互联网媒体类型text/x-qml
开发者Qt Project
格式类型脚本语言
网站qt-project.org/doc/qt-5/qmlapplications.html

QML (Qt Markup Language[3] 或 Qt Meta Language 或 Qt Modeling Language[4]) 是基於JavaScript宣告式編程程式語言,用於設計圖形使用者介面為主的應用程式。它是Qt Quick英语Qt Quick諾基亞開發的使用者介面建立套件的一部分。QML 主要用於行動應用程式,注重於觸控輸入、流暢的動畫(60張/秒)和使用者體驗。QML documents 描述元素的物件樹。

QML 元素可以透過標準 JavaScript 增強,包括這 inline 和引入.js 檔。元素可以也無縫整合和使用 Qt 框架的 C++ 元件擴展。

語言的名稱是 QML。runtime的名稱是 QQuickView。

語法、語義

[编辑]

基本語法

[编辑]

範例:

import QtQuick 1.0

 Rectangle {
     id: canvas
     width: 200
     height: 200
     color: "blue"

     Image {
         id: logo
         source: "pics/logo.png"
         anchors.centerIn: parent
         x: canvas.height / 5      
     }
 }

動畫

[编辑]
 Rectangle {
     id: rect
     width: 120; height: 200

     Image {
         id: img
         source: "pics/qt.png"
         x: 60 - img.width/2
         y: 0

         SequentialAnimation on y {
             loops: Animation.Infinite
             NumberAnimation { to: 200 - img.height; easing.type: Easing.OutBounce; duration: 2000 }
             PauseAnimation { duration: 1000 }
             NumberAnimation { to: 0; easing.type: Easing.OutQuad; duration: 1000 }
         }
     }
 }

Qt/C++ 整合

[编辑]

QML 不需要 Qt/C++ 的知識就能使用,但它可以輕鬆地擴展 Qt。

熟悉的概念

QML 提供直接訪問,從以下來自 Qt 的概念:

  • QAction – action 類型
  • QObject signals and slots – 作為在 JavaScript 中調用的函數
  • QObject properties – 作為 JavaScript 中的變數
  • QWidget – QDeclarativeView 是一個 QML-displaying widget
  • Q*Model – 直接用在資料綁定 (如 QAbstractItemModel)

Qt 信號處理式

[编辑]
 MouseArea {
     onPressed: console.log("mouse button pressed")
 }

操作方法

[编辑]

開發工具

[编辑]

由于 QML 和 Javascript 的语法相似,大多数支持 Javascript 的编辑器均可编辑 QML。但是从 Qt Creator 的 2.1 版本开始,该 IDE 提供了完整的语法高亮、代码补全、内建帮助和所见即所得编辑器。在商业版本的 Creator 中,所见即所得编辑器还会提供更多的功能。

參考資料

[编辑]
  1. ^ Qt 6.4 Released. 2022年9月29日. 
  2. ^ Qt 5.14.1 Released. 2020-01-27 [2020-03-10]. (原始内容存档于2020-04-08). 
  3. ^ Qt 4.8: QML Tutorial. [2013-10-31]. (原始内容存档于2013-11-02). 
  4. ^ Henrik Hartz (Product Manager for Qt Software at Nokia) comment on the name. 24 August 2009 [2011-06-14]. (原始内容存档于2011-07-23). 

外部連結

[编辑]
{{bottomLinkPreText}} {{bottomLinkText}}
QML
Listen to this article

This browser is not supported by Wikiwand :(
Wikiwand requires a browser with modern capabilities in order to provide you with the best reading experience.
Please download and use one of the following browsers:

This article was just edited, click to reload
This article has been deleted on Wikipedia (Why?)

Back to homepage

Please click Add in the dialog above
Please click Allow in the top-left corner,
then click Install Now in the dialog
Please click Open in the download dialog,
then click Install
Please click the "Downloads" icon in the Safari toolbar, open the first download in the list,
then click Install
{{::$root.activation.text}}

Install Wikiwand

Install on Chrome Install on Firefox
Don't forget to rate us

Tell your friends about Wikiwand!

Gmail Facebook Twitter Link

Enjoying Wikiwand?

Tell your friends and spread the love:
Share on Gmail Share on Facebook Share on Twitter Share on Buffer

Our magic isn't perfect

You can help our automatic cover photo selection by reporting an unsuitable photo.

This photo is visually disturbing This photo is not a good choice

Thank you for helping!


Your input will affect cover photo selection, along with input from other users.

X

Get ready for Wikiwand 2.0 🎉! the new version arrives on September 1st! Don't want to wait?