qml3-基本类型

int 

num 绑定父对象宽度

import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.12

Window {
    id:root
    width: 400
    height: 300
    visible: true
    title: qsTr("Hello World")

    Item{

        property int num: parent.width
        onNumChanged: {
            console.log("onNumChanged",num);
        }
    }


}

num获取父对象宽度,非动态绑定

import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.12
import QtQml 2.12
Window {
    id:root
    width: 400
    height: 300
    visible: true
    title: qsTr("Hello World")

    Item{

        property int num
        onNumChanged: {
            console.log("onNumChanged",num);
        }

        Component.onCompleted: {

            num = parent.width
        }
    }


}

var

一个通用的属性类型。
var 类型是可以引用任何数据类型的通用属性类型。
它相当于一个常规的 JavaScript 变量。 例如,var 属性可以存储数字、字符串、对象、数组和函数:

 Item {
     property var aNumber: 100
     property var aBool: false
     property var aString: "Hello world!"
     property var anotherString: String("#FF008800")
     property var aColor: Qt.rgba(0.2, 0.3, 0.4, 0.5)
     property var aRect: Qt.rect(10, 10, 10, 10)
     property var aPoint: Qt.point(10, 10)
     property var aSize: Qt.size(10, 10)
     property var aVector3d: Qt.vector3d(100, 100, 100)
     property var anArray: [1, 2, 3, "four", "five", (function() { return "six"; })]
     property var anObject: { "foo": 10, "bar": 20 }
     property var aFunction: (function() { return "one"; })
 } 
import QtQuick 2.12
import QtQuick.Window 2.12
import QtQuick.Controls 2.0
import QtQuick.Layouts 1.12
import QtQml 2.12
Window {
    id:root
    width: 400
    height: 300
    visible: true
    title: qsTr("Hello World")

    Item{

        property var obj
        onObjChanged: {
            console.log("onObjChanged",obj);
        }

        Component.onCompleted: {
            obj = 100
            obj = false
            obj = "Hello world!"
            obj = String("#FF008800")
            obj = Qt.rgba(0.2, 0.3, 0.4, 0.5)
            obj = Qt.rect(10, 10, 10, 10)
            obj = Qt.point(10, 10)
            obj = Qt.size(10, 10)
            obj = Qt.vector3d(100, 100, 100)
            obj = [1, 2, 3, "four", "five", (function() { return "six"; })]
            obj = { "foo": 10, "bar": 20 }
            obj = (function() { return "one"; })
        }
    }


}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值