检测QML中按钮的按住状态 [英] Detect press and hold of a Button in QML

查看:881
本文介绍了检测QML中按钮的按住状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户按下并按住Button时,我想打开一个上下文菜单(为方便起见,我使用Button).如果我愿意

I'd like to open a context menu when a user presses and holds a Button (I use Button for convenience). If I do

    Button
    {
        text: model.ualabel

        MouseArea
        {
            preventStealing: true
            anchors.fill: parent
            onPressAndHold: uaContextMenu.open()
        }

        ContextMenu
        {
            id: uaContextMenu
            MenuLayout
            {
                MenuItem { /**/ } 
            }
        }
    }

然后,即使press和Button无法单击,负责pressAndHold的MouseArea也会窃取所有手势.我究竟做错了什么?我正在使用Qt 4.7并导入QtQuick 1.1com.nokia.meego 1.0

then the MouseArea responsible for pressAndHold steals all gestures even though and the Button cannot be clicked. What am I doing wrong? I'm using Qt 4.7 and importing QtQuick 1.1 and com.nokia.meego 1.0

谢谢

推荐答案

我发现可以在QML的Button上模拟按下并按住:

I've found that press-and-hold can be simulated on QML's Button like this:

Button {
    id: button

    signal pressAndHold()

    Timer {
        id: longPressTimer

        interval: 2000 //your press-and-hold interval here
        repeat: false
        running: false

        onTriggered: {
            button.pressAndHold()
        }
    }


    onPressedChanged: {
        if ( pressed ) {
            longPressTimer.running = true;
        } else {
            longPressTimer.running = false;
        }
    }
}

这篇关于检测QML中按钮的按住状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆