QT 杂记

  1.按F4切换designer和Edit视图。

  2.加载同目录下的js文件:

import  "XXX.js" as   MyJs   //首字母一定要大写

  3.qml 引用的js中对象、字符串、数组的声明: 

function test(){
    var str=String(null);
    var str1=String("this is str1");
    var array=new Array;
    array.push("index is 0");
    array.push("index is 1");
    var object=Object.create(null);
    object.name="XiaoMing";
    object.sex="Man";

    console.log(str);
    console.log(str1);
    console.log(array[0]);
    console.log(array[1]);
    console.log(object.name);
    console.log(object.sex);
}

  输出如下:

  4.在qml中,声明未知类型变量:

 property var delta;

   5.一定要细心,在判断图片加载状态的时候,不是onStateChanged,是onStatusChanged。

   6.在使用鼠标悬停事件(onEntered、onExited)的时候,一定别忘了 hoverEnabled: true;

   7.qml自定义信号的连接注意事项:target是信号来源地,不是接受信号的地方

 

   //Component
    Component{
        id:buttonComponent
        Rectangle{
            id:btn
            width:80;
            height:30;
            color:"#6699cc"
            border{color:Qt.lighter(btn.color)}
            signal send(color clr); //信号声明,含参数
            MouseArea{
                anchors.fill: parent;
                onClicked: parent.send(btn.color); //点击发射信号
            }

            Text{
                anchors.centerIn: parent;
                text:"Button"
            }
        }
    }
    //loader
    Loader{
        id:btnLoad
        anchors.top:textShow.bottom;
        anchors.topMargin: 8;
        anchors.horizontalCenter: textShow.horizontalCenter;
        sourceComponent: buttonComponent;
    }

    Connections{
        target: btnLoad.item;   //loader的item,就是buttonComponent,信号来源
        onSend:{ //当send信号被触发,或者被发射,执行接下来的动作
            textShow.color=clr;
        }

    }

 8.可以这样初始化值:

 变量a,b声明:

初始化值:

结果:

 

 

 

 

转载于:https://www.cnblogs.com/ForRickHuan/p/6001915.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值