2017-03-06 196 views
0

當上下文變量發生變化時,isOn屬性是否也會在代碼的下面進行修改?QML屬性綁定

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

回答

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

提示:

+0

非常感謝你,我來試試 – yonutix