QML语法

QML 是一种用户界面规范和编程语言。它允许开发人员和设计人员创建性能高、动画流畅、视觉效果好的应用程序。QML 提供高度可读、声明式、类似 JSON 的语法,支持与动态属性绑定相结合的 JavaScript 表达式。

color颜色

  • color: "red", "green", "blue"
  • SVG颜色
  • color: "#RRGGBB"
  • color: "#AARRGGBB"

font字体

  • font.family: "Helvetica"
  • font.bold: true
  • font.italic: true
  • font.underline: true
  • font.pointSize: 10
  • font.pixelSize: 10

Item

  • anchors.fill
  • anchors.baseline
  • anchors.baselineOffset
  • anchors.left
  • anchors.right
  • anchors.top
  • anchors.bottom
  • anchors.margin
  • anchors.leftMargin
  • anchors.rightMargin
  • anchors.topMargin
  • anchors.bottomMargin
  • anchors.centerIn
  • anchors.verticalCenter
  • anchors.horizontalCenter
  • anchors.verticalCenterOffset
  • anchors.horizontalCenterOffset

Layout布局附加属性

  • alignment
  • Qt.AlignVCenter
  • Qt.AlignHCenter
  • Qt.AlignLeft
  • Qt.AlignRight
  • Qt.AlignTop
  • Qt.AlignButton
  • Qt.AlignBaseline
  • bottomMargin
  • leftMargin
  • rightMargin
  • topMargin
  • fillWidth: true
  • fillHeight: true

GridLayout网格布局

  • rows
  • colums
  • rowSpacing
  • columnSpacing

ColumnLayout网络列布局

  • spacing

RowLayout网格行布局

  • spacing

StackLayout堆栈布局

  • currentIndex

Rectangle矩形

  • width: 100
  • height: 100
  • color: "red"
  • border.width: 5
  • border.color: "red"
  • radius: 10

Text文本

  • text: "Hello"
  • color: "red"
  • font.bold: true
  • font.family: ""
  • font.italic: true
  • font.pixelSize: 10
  • font.pointSize: 10
  • font.underline: true

Button按钮

  • text: "OK"
  • onClicked: model.submit()

MouseArea鼠标处理

  • cursorShape 光标形状
  • Qt.ArrowCurse
  • Qt.CrossCursor
  • Qt.OpenHandCursor
  • onClicked: {}
  • onPressed: {}
  • onReleased: {}
  • onPressAndHold: {}

Image图片

  • source: "/images/car.png"