QtQuick学习笔记之QML鼠标事件

来源:互联网 发布:乐视 网络大电影 合作 编辑:程序博客网 时间:2024/06/06 02:33

记录Qtquick核心编程学习记录

import QtQuick 2.5
Rectangle{
    width:300;
    height:400;
    id:root;
    color:"green";
    MouseArea{
        id:mouseArea;
        anchors.fill: parent;
       acceptedButtons: Qt.LeftButton | Qt.RightButton;
       onClicked: {
           if(mouse.button == Qt.RightButton)
           {
               Qt.quit();
           }
           else if(mouse.button == Qt.LeftButton)
           {
               color = Qt.rgba( (mouse.x % 255)/255.0, (mouse.y % 255) / 255.0, 0.6, 1.0 );
           }
       }
       onDoubleClicked: {
           color = "red";
       }
    }
}

效果说明:根据鼠标左键点击颜色变化,右键退出,双击变红。

0 0
原创粉丝点击