Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

DelayButton reset after activation



  • I want to use a DelayButton to avoid accidental clicks, but I'm not interested in the checkable feature. Hence, once activated I want to un-check it to be ready to a new press.

    I tried to do this, but it does't work:

    DelayButton {
        text: "RESET"                
        onActivated: { 
            // do something
            checked = false 
        }
    }
    

    also set the checkable property to false in the definition doesn't work. What is the right way to do this?



  • Hi @Mark81
    I tried on Windows 10 (x64) and Qt versions 5.10.0, 5.10.1 and 5.11.0 and setting checked = false works?

    After activation and releasing the button, the state is reset and I can press it again until it triggers.

    import QtQuick 2.10
    import QtQuick.Window 2.3
    import QtQuick.Extras 1.4
    
    //ApplicationWindow {
    Window {
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
    
        DelayButton {
            delay: 1000
            text: "RESET"
    
            onActivated: {
                console.debug("Activated!")
                checked = false
            }
        }
    }
    


  • Found the problem. I'm using the DelayButton from QtQuick.Controls instead of the one in QtQuick.Extras because I like the rectangular shape rather than the circular one and I'm using other object from Controls. But the behavior is different, though.

    I find confusing to have the same object in two different imports... I don't know if I can live with the "extras" one. Please, would you try the very same code with:

    import QtQuick.Controls 2.2
    

    to try if it doesn't work as expected now?



  • @Mark81
    I didn't see your message because you did not directly reply to mine (or I did not get the notification), hence the delay.
    This delay did hence not come from the button^^.

    I tried with import QtQuick.Controls 2.2 and then indeed I get the same behavior as you are experiencing.

    However, I achieved the reset by simply using:

            onActivated: {
                console.debug("Activated!")
                progress = 0.0
            }
    

    Although the online Qt doc says that the progress property is read-only, it is not!
    http://doc.qt.io/qt-5/qml-qtquick-controls2-delaybutton.html

    I found a hint for this by looking at the source code:
    https://code.woboq.org/qt5/qtquickcontrols2/src/quicktemplates2/qquickdelaybutton.cpp.html#_ZN17QQuickDelayButton11setProgressEd

    Since it has a setProgress method I reckoned that it also must be exposed to QML which it apparently is. I did not look at the header file for closure about this, but since it works...


Log in to reply