0
我想在可重用的QML組件中使用默認值定義一個屬性。這裏是我的代碼迄今:QML屬性爲空
property alias value: progressBar.value
property bool error: false
property ProgressBarStyle errorStyle: ProgressBarStyle {
background: Rectangle {
radius: 2
color: "lightgray"
border.color: "gray"
border.width: 1
implicitWidth: 200
implicitHeight: 24
}
progress: Rectangle {
color: "orangered"
border.color: "red"
}
}
Layout.fillWidth: true
ProgressBar {
id: progressBar
Layout.fillWidth: true
minimumValue: 0.0
maximumValue: 100.0
style: errorStyle
}
這樣的想法是errorStyle
構造並設置爲progressBar
的style
。我知道errorStyle
的作品,因爲如果我直接在progressBar
上設置它的作品。從我可以告訴,當我運行我的程序時,問題是errorStyle
是null
。
UPDATE:
也許說明這個問題的一個更好的方法是:'PropertyChanges不支持創建狀態特定對象的「我如何繞過錯誤消息,如果我直接的PropertyChanges陣列中創建的風格,我得到
更新2:
我「已經基本放棄了這一做法,並決定嘗試使用造型來代替。這導致了另一個問題:Cannot create certain QML types in a singleton
使用組件和ID沒有工作,同樣的問題。我想替換整個樣式對象的原因是,在Mac上,默認的進度條樣式是系統定義的,從我可以看出,不透明的,所以我不能更改顏色,因此我想在那裏更改整個樣式是一個錯誤條件。 – Tim
如何在我的第二個解決方案中改變顏色? – fonZ
就像我說過的,OSX上的進度條默認是系統定義的(例如,它是動畫的),並且從我可以告訴的不是一個簡單的樣式,所以我不能只是改變顏色。 – Tim