コンテンツにスキップ

QML

出典: フリー百科事典『ウィキペディア(Wikipedia)』
QML
パラダイム 宣言型プログラミング、リアクティブプログラミング ウィキデータを編集
登場時期 2009年 (15年前) (2009)
開発者 Qt Project英語版
最新リリース 5.12 LTS/ 2018年12月6日 (5年前) (2018-12-06)[1]
影響を受けた言語 JavaScriptExtensible Application Markup LanguageJavaScript Object NotationQt ウィキデータを編集
ウェブサイト QML Applications
拡張子 .qml
テンプレートを表示

QML (QtModeling Language[2]) QMLJavaScriptCSSJSONQtUIQt QuickQt Quick (60fps) 使QMLQt 3D[3]3D使QMLQtQML () (FolderListModelXmlListModel) () () [4]

QMLJavaScript使Qt使C++

QMLV4JavaScript[ 1]Qt 5.2使[5][6]Qt Quick2DUIQt DeclarativeQt Declarative

QMLJavaScriptQt Quick[7]QMLQML[8]

[]


KDE Plasma 4[9]KDE Plasma 5

Liri

SDDM

reMarkable[10][11]

Unity2D[12]

Sailfish OS[13][14]

BlackBerry 10[15]

MeeGo[16]

Maemo[17]

Tizen[18]

Mer[19]

Ubuntu Touch[20]

Lumina[21]

[]

[]


:
 import QtQuick 2.9  // import from Qt 5.9

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

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

RectangleImage2: Imagesourcepics/logo.png

id

idididRectanglemyRectid2RectanglewidthmyRect.widthRectanglewidth2RectanglewidthRectanglewidth
 Item {
     Rectangle {
         id: myRect
         width: 120
         height: 100
     }
     Rectangle {
         width: myRect.width
         height: 200
     }
 }

id小文字アンダースコアで始まり、ラテン文字数字・アンダースコア以外の文字は使用できない。

プロパティバインディング[編集]

プロパティバインディングは、宣言的な方法でプロパティの値を指定する。リアクティブプログラミング英語版のパラダイムに従って、他のプロパティまたはデータの値が更新された場合に、プロパティの値が自動的に更新される。

プロパティバインディングはJavaScriptのが割り当てられるたびにQMLに暗黙的に作成される。以下の例では、2つのプロパティバインディングを使用して、長方形の大きさとotherItemの大きさを繋げている。

 Rectangle {
     width: otherItem.width
     height: otherItem.height
 }

QMLの処理系は標準に準拠したJavaScriptエンジンを拡張したものなので、有効なJavaScriptの式は全てプロパティバインディングとして使用することができる。プロパティバインディングはオブジェクトのプロパティに接続したり、関数呼び出しを作成したり、DateMathなどのの組み込みオブジェクトを使用することもできる。

例:

 Rectangle {
     function calculateMyHeight() {
         return Math.max(otherItem.height, thirdItem.height);
     }
     anchors.centerIn: parent
     width: Math.min(otherItem.width, 10)
     height: calculateMyHeight()
     color: width > 10 ? "blue" : "red"
 }

状態[編集]




:

myRect 0, 0 moved50, 50 moved
 import QtQuick 2.0

 Item {
     id: myItem
     width: 200; height: 200

     Rectangle {
         id: myRect
         width: 100; height: 100
         color: "red"
     }
     states: [
         State {
             name: "moved"
             PropertyChanges {
                 target: myRect
                 x: 50
                 y: 50
             }
         }
     ]
     MouseArea {
         anchors.fill: parent
         onClicked: myItem.state = 'moved'
     }
 }

状態の変更はトランジションを使うことでアニメーションにすることができる。

例えば、下記のコードを上のItemに追加すると、movedへの遷移を動的なものにすることができる。

 transitions: [
     Transition {
         from: "*"
         to: "moved"
         NumberAnimation { properties: "x,y"; duration: 500 }
     }
  ]

アニメーション[編集]


QMLrealintcolorrectpointsizevector3d

QML3

PropertyAnimation使便


 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++QtQObjectC++QML

[]


QObject signals - JavaScript

QObject slots - JavaScript

QObject properties - JavaScript

QWindow - QML

Q*Model - 使 (QAbstractItemModel)[22]

[]


JavaScriptMouseArea
 MouseArea {
     onPressed: console.log("mouse button pressed")
 }

on

[]


QMLJavaScriptJavaScriptWYSIWYGQt Creator 2.1

QMLQMLQML () C++QML

脚注[編集]

注釈[編集]

  1. ^ V8をカスタマイズしたJavaScriptエンジン。

出典[編集]



(一)^ Qt 5.12 LTS Released.  Qt Blog (2018126). 20181213

(二)^ Qt Declarative API Changes - 20141113

(三)^ Qt 3D Overview.  The Qt Company. 20181213

(四)^ All QML Types.  The Qt Company. 20181213

(五)^ Lars Knoll (2013415). Evolution of the QML engine, part 1. 20181213

(六)^ What's New in Qt 5.2.  The Qt Company. 20181213

(七)^ Qt Quick Compiler.  The Qt Company. 20181213

(八)^ Deploying QML Applications.  The Qt Company. 20181213

(九)^ Development/Tutorials/Plasma4/QML/GettingStarted.  KDE. 20181213

(十)^ Developing for the reMarkable tablet.  KDE (2017121). 20181213

(11)^ reHackable-HelloWorld.  GitHub. 20181213

(12)^ Michael Larabel (201334). Ubuntu's Unity Written In Qt/QML For "Unity Next". 20181213

(13)^ Tutorial - Combining C++ with QML.  SailfishOS. 20181213

(14)^ Tutorial - QML Live Coding With Qt QmlLive.  SailfishOS. 20181213

(15)^ QML fundamentals.  BlackBerry. 20181213

(16)^ Ash (2011223). MeeGo and Qt / QML demos assault MWC. 20181213

(17)^ QML.  Maemo. 20181213

(18)^ Qt Launches on Tizen with Standard Look and Feel.  Qt for Tizen Blog (2013520). 20181213

(19)^ Mer Project.  Mer Project. 20181213

(20)^ QML - the best tool to unlock your creativity.  Canonical. 20181213

(21)^ Josh Smith (201852). Looking at Lumina Desktop 2.0. 20181213

(22)^ QAbstractItemModels in QML views.  The missing pieces (2010422). 20181213

関連項目[編集]

外部リンク[編集]

利用方法[編集]