爲什麼無法爲款式定義別名?例如款式別名
Button {
property alias color: theText.color
style: ButtonStyle {
label: Text {
id: theThext
}
}
}
給出了一個
QML無效別名參考無法找到ID爲
theText
爲什麼無法爲款式定義別名?例如款式別名
Button {
property alias color: theText.color
style: ButtonStyle {
label: Text {
id: theThext
}
}
}
給出了一個
QML無效別名參考無法找到ID爲
theText
類似於this answer,這是因爲該alias
是指該項目是動態加載。像Label
這樣的組件類型就是:Component
s。它們是用於創建實際樣式Item
的模板,它們實際上是使用Loader
加載的。
這裏是我的解決方案(例如工作):
//MyCustomBtn.qml
import QtQuick 2.0
import QtQuick.Controls 1.2
import QtQuick.Controls.Styles 1.2
Button {
function setFontColor(fontColor){color_ = fontColor}
property string color_: "black"
style: ButtonStyle {
label: Text {
color: color_
text: control.text
}
}
}
//MyTest.qml
MyCustomBtn {
text: qsTr("Hello World")
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
Component.onCompleted: setFontColor("red")
}
在默認字體大小
Button {
property int fontPixelSize: 0
style: ButtonStyle {
label: Text {
font.pixelSize: fontPixelSize ? fontPixelSize : font.pixelSize
text: control.text
}
}
排序相關的問題:http://stackoverflow.com/questions/14345552/how-to - 創建別名內中繼器,elemets – Mitch