qt4 qml MouseArea

三十三、体验QML演示程序

三十四、Qt Quick Designer介绍

三十五、QML组件



 添加的按钮的qml组件
import QtQuick 1.0

Rectangle {
    width: 100
    height: 62
    id:myButton
    radius: 10;
    color: "blue"
    signal clicked()
    MouseArea{
        id:myMouseArea;
        anchors.fill: parent
        onClicked:myButton.clicked()
     }
}

以上的表示MouseArea收到用户点击即onClicked时会执行myButton.clicked()函数

在mainwondow中添加
Rectangle {
    id:mainWindow
    width: 280
    height: 300
    ...
   
    Button {
        id: button1
        x: 180
        y: 147
        onClicked:mainWindow.state = "状态1"
    }




}
这里相当于重写myButton.clicked()函数,即进入状态1


MouseArea 的一些事件,
在   MouseArea 内部写信号函数 onClicked: {Qt.quit();}
    MouseArea {
        id: mousearea1
        x: 36
        y: 219
        width: 206
        height: 57
        anchors.rightMargin: 38
        anchors.bottomMargin: 24
        anchors.leftMargin: 36
        anchors.topMargin: 219
        anchors.fill: parent
        onClicked: {
            Qt.quit();
        }
    }
直接在State内部写when: myMouseArea.pressed
 State {
            name: "状态1"
            when: myMouseArea.pressed
            PropertyChanges {
                target: text1
                x: 124
                y: 201
                anchors.verticalCenterOffset: 34
                anchors.horizontalCenterOffset: 16
                rotation: 218
                scale: 0.9
                transformOrigin: "Center"
                font.pointSize: 19
            }
...
}




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值