qml gradient 橫向漸變


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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM