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

Automatic touch simulation on rectangle component in QML



  • I wanted to simulate automatic click event on rectangle component in QML code.

    I have requirement as bellow.
    .qml file:

    import QtQuick 2.6
    import QtQuick 2.6
    import QtQuick.Window 2.2
    import QtQuick.Controls 2.1
    import QtQuick.Controls 2.1
    Window {
    id :root
    visible: true
    width: 640
    height: 480

    Rectangle{
        id:child1
        color: "green"
        height: 100
        width:100
        x:20
        y:60
        MouseArea{
            visible: true
            anchors.fill: parent
            id:child1MA
            onClicked: {
                console.log("Clicked")
            }
    

    Timer {
    interval: 2000
    repeat: false
    running: true
    onTriggered:
    //call function simulate touch here//
    }
    }
    }

    so when click simulation happens on rectangle, "Clicked" message has to log on consol

    thank you

    Edit raven-worx: moved topic


  • Qt Champions 2017

    Mouse Area has signals and signals can be called directly. Based on your condition you can call the MouseArea signals directly.


Log in to reply