其他分享
首页 > 其他分享> > qml3-基本类型

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"; })
        }
    }


}

标签:基本,10,QtQuick,obj,var,qml3,类型,import,property
来源: https://blog.csdn.net/LIJIWEI0611/article/details/123607845