• 《Qt Quick 4小时入门》学习笔记


    http://edu.csdn.net/course/detail/1042/14804?auto_start=1
     

    Qt Quick 4小时入门

    第五章:Qt Quick里的信号与槽
     
    QML中的三种信号连接方式:

     
    方式一:在组件内通过on<SignalName>的方式

    importQtQuick2.0
    importQtQuick.Window2.0;
    
    
    Window{
    id: win;
    visible: true;
    width: 300;
    height: 200;
    color: "black";
    
    
    Text{
    id: txt;
    text:"hello,superSun";
    font.pointSize:20;
    color:"yellow";
    }
    
    
    //信号处理器的第一种写法(看样子就是其他语言中的事件)
    onWidthChanged:{
    txt.x=(win.width-txt.width)/2;
    }
    
    
    //信号处理器的第二种写法
    onHeightChanged:heightChanged();
    
    
    functionheightChanged(){
    txt.y=(win.height-txt.height)/2;
    }
    }

    注:
    1、针对上面用到的字体大小的设置说明一下,在QFont当中有两种方式设置字体大小,一种是PixelSize,另一种是PointSize,Point实际是磅,也就是 1/72 inch。

    pixel size 是所占的像素大小,这样有一个缺点,有些显示器的分辨率(dpi)比较大,那么单位长度中的像素点就比较多,这样一个字所占的长度就会比较少;而 point size 则规定了实际中我们肉眼看到的字体的大小,他和pixel无关,和显示器无关。

    2、信号处理器,等价于Qt中的槽。

     

    方式二:通过信号的connect方法


    importQtQuick2.0
    importQtQuick.Window2.0
    importQtQuick.Controls2.0
    
    
    Window{
    id:win;
    visible:true;
    width:300;
    height:200;
    
    
    Button{
    id:btn;
    text:"Quit";
    }
    
    
    functionquitFunc(){
    Qt.quit();
    }
    
    
    Component.onCompleted:{
    btn.clicked.connect(quitFunc); 
    // quitFunc后面不写括号
    }
    }
    
    
    方式三:通过Connections

    importQtQuick2.0
    importQtQuick.Window2.0
    importQtQuick.Controls2.0
    
    
    Window{
    id:win;
    visible:true;
    width:300;
    height:200;
    
    
    Button{
    id:btn;
    text:"Quit";
    }
    
    
    functionquitFunc(){
    Qt.quit();
    }
    
    
    Connections{
    target:btn;
    onClicked:quitFunc(); // quitFunc后面写括号
    }
    }
    
    

     





  • 相关阅读:
    C#博客随笔之四:使用C#模拟办公网登录HttpClient的使用
    C#博客随笔之三:Linq in C#
    C#博客随笔之二:wp开发之弹出对话框
    C#博客随笔之一:使用C#的第一个WP程序
    Fedora15命令速查手册
    乐观是一种智慧
    完全教程 Aircrackng破解WEP、WPAPSK加密利器
    FreeBSD常用命令大全
    Linux 网络管理员指南——前言
    API
  • 原文地址:https://www.cnblogs.com/sdsunjing/p/5896271.html
Copyright © 2020-2023  润新知