Cpper
C/C++高级工程师 Android高级软件工程师 IT集成工程师 音频工程师 熟悉c,c++,java,c#,py,js,asp等多种语言 程序猿
import QtQuick 2.2  
import QtQuick.Controls 1.1
    
Canvas
{
    id: root
    width: 200; height: 200
    onPaint:
    {
        var ctx = getContext("2d")
        ctx.lineWidth = 2
        ctx.strokeStyle = "blue"
        ctx.fillStyle = "red"
        ctx.beginPath()
            ctx.moveTo(50,50)
            ctx.lineTo(150,50)
            ctx.lineTo(150,150)
            ctx.lineTo(50,150)
        ctx.closePath()
        ctx.fillRect(10,10,10,10)
        ctx.strokeRect(20,20,10,10);
        ctx.fill()
        ctx.stroke()
    }
}
使用渐变
import QtQuick 2.2  
import QtQuick.Controls 1.1
    
Canvas
{
    id: root
    width: 200; height: 200
    onPaint:
    {
        var ctx = getContext("2d")
        var gradient = ctx.createLinearGradient(0,0,200,200)
        gradient.addColorStop(0,"blue")
        gradient.addColorStop(0.5,"red")
        gradient.addColorStop(1,"yellow")
        ctx.fillStyle = gradient
        ctx.fillRect(10,10,100,100)
    }
}
增加阴影
import QtQuick 2.2  
import QtQuick.Controls 1.1
    
Canvas
{
    id: root
    width: 200; height: 200
    onPaint:
    {
        var ctx = getContext("2d")
        ctx.shadowColor = "black";
        ctx.shadowOffsetX = 2;
        ctx.shadowOffsetY = 2;
        var gradient = ctx.createLinearGradient(0,0,200,200)
        gradient.addColorStop(0,"blue")
        gradient.addColorStop(0.5,"red")
        gradient.addColorStop(1,"yellow")
        ctx.fillStyle = gradient
        ctx.fillRect(10,10,100,100)
    }
}
posted on 2015-08-20 14:11 ccsdu2009 阅读(569) 评论(0)  编辑 收藏 引用 所属分类: QT编程

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理