天天看點

qt漸變色一個簡單的QT程式

一個簡單的QT程式

import QtQuick 2.9
import QtQuick.Window 2.2

Window {
    visible: true
    width: 640
    height: 480
    title: qsTr("Hello World")
    Rectangle {
        width: 300;
        height: 200;
        color: "blue"
        Item {
            id:gradientGroup;
            Rectangle {
                x:20;
                y:20;
                width: 120;
                height: 120;
                gradient:Gradient {
                    GradientStop {position:0.0;color: "#202020";}
                    GradientStop {position:1.0;color:"#A0A0A0";}
            }
        }
            Rectangle {
                 x:160;
                 y:20;
                 width: 120;
                 height: 120;
                 rotation: 90;
                 gradient:Gradient {
                     GradientStop {position:0.0;color: "red";}
                     GradientStop {position:1.0;color:"#A0A0A0";}
            }
        }
    }
    Component.onCompleted: {
        console.log("visible children:",
                    gradientGroup.visibleChildren.length);
        console.log("children:",gradientGroup.children.length);
        for(var i=0;i<gradientGroup.children.length;i++)
        {
            console.log("child",i,"x=",
                        gradientGroup.children[i].x);
        }
     }
  }
}

           

程式運作結果

qt漸變色一個簡單的QT程式
上一篇: qt學習記錄1
下一篇: Qt: 漸變填充