QT/QML 简介

QT/QML

QML(Qt Meta Language 或 Qt Modeling Language)是一种用于设计用户界面的声明式语言,主要用于Qt框架。QML允许开发者以一种直观的方式描述用户界面,同时与JavaScript结合使用,以便实现复杂的逻辑和动态行为。以下是一些QML的基本概念和示例代码:

基本概念

  1. 元素(Elements) :QML的基本构建块,例如RectangleTextButton等。
  2. 属性(Properties) :元素的特性,例如widthheightcolor等。
  3. 信号和处理器(Signals and Handlers) :用于处理事件,例如onClicked
  4. JavaScript:用于实现复杂的逻辑。

示例代码

以下是一个简单的QML示例,展示了一个带有按钮和文本的窗口:

qml 复制代码
import QtQuick 2.15
import QtQuick.Controls 2.15

ApplicationWindow {
    visible: true
    width: 640
    height: 480
    title: "QML 示例"

    Rectangle {
        width: 200
        height: 100
        color: "lightblue"
        anchors.centerIn: parent

        Text {
            text: "Hello, QML!"
            anchors.centerIn: parent
        }

        Button {
            text: "点击我"
            anchors.top: parent.bottom
            anchors.horizontalCenter: parent.horizontalCenter
            onClicked: {
                console.log("按钮被点击了")
            }
        }
    }
}
相关推荐
用户805533698031 天前
不止三件套:QObject 属性系统全关键字与运行时反射!
c++·qt
xcyxiner1 天前
DicomViewer (vcpkg Windows和ubuntu编译)7
qt
Quz6 天前
QML Hello World 入门示例
qt
xcyxiner9 天前
DicomViewer (dcmtk读取dcm文件)5
qt
xcyxiner10 天前
DicomViewer (后台线程处理文件)4
qt
xcyxiner10 天前
DicomViewer (添加模型类)3
qt
xcyxiner11 天前
DicomViewer (目录调整) 2
qt
xcyxiner11 天前
dcmtk vtk vtk-dicom(gdcm) 编译(debug) v2
qt
桥田智能13 天前
桥田智能 QT-650S:面向白车身焊装的 800kg 重载快换解决方案
开发语言·qt·系统架构
森G13 天前
75、服务器源码解析---------云视频服务项目
linux·服务器·网络·c++·qt