Qml Buttons and onClicked



  • Right now I have Qml code sending a signal to my c++ code that sends a true or false. When the button is clicked it sends a signal containing true. This is working how I want it to but I would like to send a false signal when the button is let go.

    So basically I am asking how you would send a true signal when the button is held down by the user and then send a false signal when the user lets go.

    I have looked into using states but I haven't found much information about them.

    Thanks for any help that can be offered. Below is my qml code.

    @import QtQuick 2.0
    import QtQuick.Window 2.0
    import QtQuick.Controls 1.0
    import QtQuick.Layouts 1.0
    import QtQuick.Dialogs 1.0
    import QtQuick.Particles 2.0

    Item {
    id: item
    width: 300; height: 300

    signal qmlSignal(bool msg)
    
    Rectangle {
        id: rectangle1
        x: 0
        y: 0
        width: 300
        height: 300
        color: "#c02323"
    
        Button {
            id: button1
            x: 0
            y: 0
            width: 300
            height: 300
            text: "button"
            onClicked: item.qmlSignal(true)
        }
        
    }
    

    }
    @



  • You can use the signal handler

    @onPressedChanged@



  • I just made it a mouse area and used onPressed and onReleased


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.