QML之Rectangle屬性

QML的Rectangle組件,顧名思義就是描繪一個矩形,一個可視化的對象。外加設置屬性來達到我們想要的效果。常用的有矩形的顏色,邊框顏色,圓角等設置。


Rectangle{
        id:rect_buttom  //id,一個名字,用來識別
        x:100     //相對父窗口的座標
        y:100
        width: 200  //設置矩形的寬度
        height: 200 //設置矩形的高度
        visible: true //可見屬性設置。true爲可見,默認爲true
        color: "red"  //設置矩形的顏色,可以用英文單詞也可以用RGB,"#rrggbb"來設置
        //color: "#667788"
        radius: 5  //設置矩形圓角弧度
        border.color: "green" //設置邊框的顏色
        border.width: 5       //設置邊框的大小
        smooth: true          //設置平滑度,默認是false
        clip:true             //裁剪,默認false,表示如果它的子窗體超過本窗體的顯示範圍則超出去的部分不顯示


        gradient: Gradient { //漸變屬性
            GradientStop{//從上到下顏色漸變,需要從做到右使用屬性rotation設置90即可
                position: 0.0; color: "red"
            }
            GradientStop{
                position: 1.0; color: "blue"


            }


        }


        Rectangle{ //設置屬性與父窗體不同,用於對比
            id:hh
            x:100 //相對父窗體的座標
            y:100
            width: 250
            height: 250
            color: "#667788"
            rotation: 45
        }


        Rectangle{ //
            id:bb
            anchors.centerIn: parent //設置居中顯示
            width: 80
            height: 60
            color: "yellow"
            opacity: 0.5  //設置透明度,0-1,0爲完全透明,1表示不透明.
            rotation: 45   //設置矩形的旋轉度,旋轉中心爲矩形中心


        }


    }



注:有問題請積極提出

發佈了30 篇原創文章 · 獲贊 29 · 訪問量 6萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章