zoukankan      html  css  js  c++  java
  • QML手动连接信号槽【Connections】

    1、使用Connections

    import QtQuick 2.6
    import QtQuick.Window 2.2
    import QtQuick.Controls 1.4
    Window {
        visible: true
         640
        height: 480
        title: qsTr("Hello World")
    
        Text {
            id: text1;
            text: qsTr("text1");
            anchors.top: parent.top;
            anchors.topMargin: 10;
            anchors.horizontalCenter: parent.horizontalCenter;
            anchors.centerIn: parent;
            font.pixelSize: 20;
            color: "red";
        }
        Text {
            id: text2;
            text: qsTr("text2");
            anchors.top: text1.bottom;
            anchors.topMargin: 10;
            anchors.horizontalCenter: parent.horizontalCenter;
            font.pixelSize: 20;
        }
        Button{
            id:btn;
            text: "btn";
            anchors.horizontalCenter: parent.horizontalCenter;
            anchors.top:text2.bottom;
            anchors.topMargin: 10;
        }
    
        Connections{
            target: btn;
            onClicked:{
                text1.color=Qt.rgba(Math.random(),Math.random(),Math.random(),1);
                text2.color=Qt.rgba(Math.random(),Math.random(),Math.random(),1);
            }
        }
    }

     上述代码等于【在btn的onClicked里直接加改变颜色的代码】

    import QtQuick 2.6
    import QtQuick.Window 2.2
    import QtQuick.Controls 1.4
    Window {
        visible: true
         640
        height: 480
        title: qsTr("Hello World")
    
        Text {
            id: text1;
            text: qsTr("text1");
            anchors.top: parent.top;
            anchors.topMargin: 10;
            anchors.horizontalCenter: parent.horizontalCenter;
            anchors.centerIn: parent;
            font.pixelSize: 20;
            color: "red";
        }
        Text {
            id: text2;
            text: qsTr("text2");
            anchors.top: text1.bottom;
            anchors.topMargin: 10;
            anchors.horizontalCenter: parent.horizontalCenter;
            font.pixelSize: 20;
        }
        Button{
            id:btn;
            text: "btn";
            anchors.horizontalCenter: parent.horizontalCenter;
            anchors.top:text2.bottom;
            anchors.topMargin: 10;
            onClicked: {
                text1.color=Qt.rgba(Math.random(),Math.random(),Math.random(),1);
                text2.color=Qt.rgba(Math.random(),Math.random(),Math.random(),1);
            }
        }
    }

     2、使用signal.connect

  • 相关阅读:
    阿里开源混沌工程工具 ChaosBlade
    十天入门java教程 Day01
    如何破解IDEA
    Locust压力测试使用总结
    python+requests接口自动化测试框架实例详解教程
    一个完整的性能测试流程
    jmeter测试报告汉化及脚本编写
    tomcat的日志文件权限与启动用户的权限不一致
    Linux下部署开源版“禅道”项目管理系统
    ELK原理与介绍
  • 原文地址:https://www.cnblogs.com/judes/p/9431361.html
Copyright © 2011-2022 走看看