zoukankan      html  css  js  c++  java
  • Qt-QML-电子罗盘

    使用QML中的Canvas实现电子罗盘绘制,效果图如下

    一个简单的电子罗盘,红色N极。其中中间飞机表示当前的指向,

    还是比较简单的,直接上代码吧

    /*
    作者:张建伟
    时间:2018年4月27日
    简述:电子罗盘界面实现
    */
    importQtQuick2.0
    
    
    Rectangle
    {
    id:root
    width:200
    height:200
    anchors.centerIn:parent
    color:"transparent"
    
    
    propertyintm_Angle:0
    
    
    Rectangle
    {
    width:parent.width
    height:parent.height
    color:"transparent"
    rotation:root.m_Angle
    Canvas
    {
    anchors.fill:parent
    onPaint:
    {
    varctx=getContext("2d");
    //绘制圆圈
    ctx.lineWidth=2;
    ctx.strokeStyle="#FFFFFF";
    ctx.globalAlpha=1.0;
    ctx.beginPath();
    ctx.arc(width/2,width/2,width/2-2,0,2*Math.PI);
    ctx.stroke();
    ctx.restore();
    for(vari=0;i<36;i++)
    {
    ctx.save();
    ctx.translate(width/2,height/2);
    ctx.rotate(i*10*Math.PI/180);
    ctx.beginPath();
    if(i%9==0)
    {
    ctx.moveTo(0,-width/2+12);
    ctx.lineTo(0,-width/2+2);
    }
    else
    {
    ctx.moveTo(0,-width/2+10);
    ctx.lineTo(0,-width/2+2);
    }
    ctx.stroke();
    ctx.restore();
    }
    }
    }
    Rectangle
    {
    width:20
    height:20
    anchors.horizontalCenter:parent.horizontalCenter
    anchors.top:parent.top
    anchors.topMargin:12
    rotation:-parent.rotation
    color:"#00000000"
    Text{
    anchors.centerIn:parent
    font.family:"微软雅黑"
    font.pixelSize:14
    color:"#FF0000"
    text:qsTr("N")
    }
    }
    Rectangle
    {
    width:20
    height:20
    anchors.verticalCenter:parent.verticalCenter
    anchors.right:parent.right
    anchors.rightMargin:12
    color:"#00000000"
    rotation:-parent.rotation
    Text{
    anchors.centerIn:parent
    font.family:"微软雅黑"
    font.pixelSize:14
    color:"#FFFFFF"
    text:qsTr("E")
    }
    }
    Rectangle
    {
    width:20
    height:20
    anchors.verticalCenter:parent.verticalCenter
    anchors.left:parent.left
    anchors.leftMargin:12
    color:"#00000000"
    rotation:-parent.rotation
    Text{
    anchors.centerIn:parent
    font.family:"微软雅黑"
    font.pixelSize:14
    color:"#FFFFFF"
    text:qsTr("W")
    }
    }
    Rectangle
    {
    width:20
    height:20
    anchors.horizontalCenter:parent.horizontalCenter
    anchors.bottom:parent.bottom
    anchors.bottomMargin:12
    color:"#00000000"
    rotation:-parent.rotation
    Text{
    anchors.centerIn:parent
    font.family:"微软雅黑"
    font.pixelSize:14
    color:"#FFFFFF"
    text:qsTr("S")
    }
    }
    Rectangle
    {
    width:50
    height:50
    color:"transparent"
    rotation:-parent.rotation
    anchors.centerIn:parent
    Image{
    anchors.fill:parent
    source:"file:Images/Su_33_Pointer.png"
    }
    }
    
    
    }
    }
    
    
    

  • 相关阅读:
    设计模式了解
    三次握手
    网络安全常见术语
    threading.Thread 子线程强制停止
    黑帽SEO入门
    Chrome(谷歌)浏览器永久关闭恢复页面提示框(记录)
    FTP文件夹错误:【打开FTP服务器上的文件夹时发生错误。请检查是否有权限访问该文件夹】
    jenkins启动失败,查看状态提示active(exited)
    jenkins打包vue项目报错-未解决
    jenkins迁移报错处理
  • 原文地址:https://www.cnblogs.com/DreamDog/p/9159965.html
Copyright © 2011-2022 走看看