【Qt之Quick模块】5. QML基本类型及示例用法

QML格式

QML基本类型

在 QML 中,有以下基本类型:

  1. int:整数类型。
cpp 复制代码
Rectangle {
    function myFunction() {
        // 输出 debug 信息
        console.log("1+1 =" + (1+1));
    }

    Component.onCompleted: {
        myFunction();
    }
}

结果:

  1. real:浮点类型。

  2. double:双精度浮点类型。

  3. string:字符串类型。

cpp 复制代码
Rectangle {
    function myFunction() {
        // 输出 debug 信息
        console.log("helloworld");
    }

    Component.onCompleted: {
        myFunction();
    }
}

结果:

  1. bool:布尔类型。

  2. color:颜色类型,用于表示颜色的RGBA值。

  3. var:通用类型,可以表示任意类型的数据。

cpp 复制代码
    Item {
        property var myVar: "Hello World"

        Component.onCompleted: {
            console.log(myVar) // 输出 "Hello World" 到控制台
        }
    }

结果:

  1. date:日期类型。
cpp 复制代码
Rectangle {
    Item {
        property var currentDate: new Date()

        Component.onCompleted: {
            console.log(currentDate.toString()) // 输出当前日期和时间到控制台
        }
    }
}

结果:

  1. point:点类型,用于表示二维空间中的点。
cpp 复制代码
Item {
    width: 200
    height: 200

    property var point: Qt.point(50, 100)

    Component.onCompleted: {
        console.log(point.x, point.y) // 输出点对象的坐标值到控制台
    }
}

结果:

  1. size:尺寸类型,用于表示宽度和高度。
cpp 复制代码
Item {
    width: 200
    height: 200

    property size var_size: Qt.size(0, 2)

    Component.onCompleted: {
        console.log(var_size) // 输出点对象的坐标值到控制台
    }
}

结果:

  1. rect:矩形类型,用于表示矩形区域的左上角坐标和宽高。
cpp 复制代码
Item {
    width: 200
    height: 200

    property rect var_rect: Qt.rect(0, 0, 1, 2)

    Component.onCompleted: {
        console.log(var_rect) // 输出点对象的坐标值到控制台
    }
}

结果:

相关推荐
IvanCodes20 分钟前
Python 数据处理(十三):JSON、CSV 与数据序列化
开发语言·python
Setsuna_F_Seiei1 小时前
前端转型 Agent 开发 05 之 Agent Hooks 与 Checkpointer(让 Agent 从全自动转变人为可掌控)
前端·agent·ai编程
aramae2 小时前
MySQL复合查询(8)
java·c语言·开发语言·后端·算法
百万蹄蹄向前冲3 小时前
风扇转了一晚上MVP专家团翻车事故
前端·人工智能
默_笙3 小时前
🏛 给 AI 配一间办公室:Harness Engineering 六大模块与它的实现
前端·javascript
linux_cfan4 小时前
videojs v10 源代码系列解读:14 · 谓词守卫:在运行时安全地调用能力
前端·javascript·音视频
qq_2518364574 小时前
springboot vue3 开发实现 拼豆管理系统
java·开发语言·ai编程
kyriewen5 小时前
我扒了 10,221 条 JD:腾讯技术岗 75% 在要 AI
前端·人工智能·ai编程
郑州光合科技余经理5 小时前
同城外卖小程序开发:下单成功后,后台导出能不能对上用户端状态
开发语言·前端·git·后端·uni-app·php·ai编程
知识分享小能手5 小时前
C++ 学习教程,从入门到精通,C++ 入门知识 — 完整知识点(1)
开发语言·c++·学习