Qt World Summit: Register Today!

Continuously check something while mouse area is pressed

  • Hi! My first topic here! Anyway, here's my problem:

    @Button {
    id: rightkey
    x: 104
    y: 49
    normalImage: "Images/right1.png"
    pressedImage: "Images/right2.png"

        onPressed: {
            if (!player.rightCollide)
                player.status = "run_r";
        onReleased: player.status = "idle_r";

    The Button element is just an Image element with a MouseArea inside it. The problem lies on onPressed. You can see above that it checks if the condition is false but what I need is checking that condition continuously while the button is pressed. Do I need to do something else to achieve that?

    Thank you in advance. Hope you can help me with this.

  • You could use the onPressed: action to start a repeating Timer which does your check. Then use the onReleased: action to stop the timer.

  • Haven't thought of that. Thanks mlong! Be trying it later.

  • No problem! I've done something similar before and it worked great. Good luck!

Log in to reply