QML属性绑定

时间:2017-03-06 14:31:40

标签: javascript qml qtquick2

当上下文变量发生变化时,isOn属性是否也在下面的代码中进行了修改?

property bool isOn: {
    if(context === undefined)
        return false;
    return true
}

1 个答案:

答案 0 :(得分:3)

诀窍是,尝试一下:

import QtQuick 2.7
import QtQuick.Controls 2.0

ApplicationWindow {
    id: appWindow
    width: 500
    height: 800
    visible: true

    property bool isOn: {
        if(context === undefined)
            return false;
        return true
    }
    property var context
    Button {
        text: isOn
        onClicked: (context ? context = undefined  : context = 1)
    }
}

提示: