Rectangle {
gradient: Gradient {
GradientStop {
color: "#333"
position: 0
}
GradientStop {
color: "#222"
position: 1
}
}
}
上面代碼定義的漸變是從上到下的漸變。左右橫向漸變則不太好實現,看網上教程有說進行旋轉,但總感覺不是正常的解決方法。
搜了下資料發現LinearGradient可以實現,示例代碼如下
LinearGradient {
anchors.fill: parent
start: Qt.point(0, 0)
end: Qt.point(300, 0)
gradient: Gradient {
GradientStop { position: 0.0; color: "white" }
GradientStop { position: 1.0; color: "black" }
}
}
更多資料參考:http://doc.qt.io/qt-5/qml-qtgraphicaleffects-lineargradient.html
