Search code examples
pythonqtpyqtqmlpyside2

How to create QML button, which emits a constant signal while its pressed


I have a joystick with 4 buttons.

I need to call some short singleshot increment function again and again while i hold a button, so, i need a button, which emits a constant signal, while pressed.

I've tried onPressAndHold, but it's just emits only one signal after certain amount of time, when I need to emit a constant signal via pressing the button. (i just want to call a singleshot function every certain amount of time).

Of cource i can write a 'flag' button, which will start the function with a loop, which will work until flag is changed with onReleased method. But, i don't want to rewrite the function + using loops is not good for this project bc of it's overloaded architecture.


Solution

  • You can use autoRepeat and autoRepeatDelay.

    Button {
        text: "Press"
        autoRepeat: true
        autoRepeatDelay: 100
    
        onPressed: console.log("pressing")
    }