QML MouseEvent



  • Hello all !!
    I am having two qml files, main.qml & task.qml. I am launching task.qml on a mouse click from main.qml using Qt.createComponent.

    The mouseEvent from task.qml passes to main.qml.
    My understanding is when I create the dynamic component the mouse events from task.qml will not pass to main.qml.
    Kindly clear me If I am wrong.
    kindly help me to fix it.

    Thanks & Regards,
    Narayanan K


  • Moderators

    AFAIK, QML engine makes no distinction between statically and dynamically generated components.

    If you want to stop a mouseEvent being passed around, you need to accept it at some level with:
    @
    // for example:
    onClicked: {
    mouse.accepted = true;
    }
    @


  • Moderators

    AFAIK, QML engine makes no distinction between statically and dynamically generated components.

    If you want to stop a mouseEvent being passed around, you need to accept it at some level with something like this:
    @
    onClicked: {
    mouse.accepted = true;
    }
    @



  • Hi,

    The following are my qml codes. I am creating the task component on a mouse click on main.qml.

    Can you please specify where I have to accept/reject the mouse events.

    main.qml
    @

    import QtQuick 2.0
    import "Test.js" as Test
    import "Global.js" as GlobalJS

    Rectangle {
    id: root
    width:800
    height:480

    Image {
        id: bg
        source: "../../resources/images/Home_Screen/bg.png"
        x: 0
        y: 0
        opacity: 1
    }
    
    
    Image 
    {
        id: task_manager
        source: "../../resources/images/Home_Screen/task_manager.png"
        x: 219
        y: 342
        opacity: 1
    

    MouseArea
    {
    anchors.fill: parent
    onClicked:
    { GlobalJS.dynamic_component_task=Qt.createComponent("TaskManager.qml").createObject(root, {});
    }
    }
    }

    Image 
    {
        id: about
        source: "../../resources/images/Home_Screen/about.png"
        x: 544
        y: 297
        opacity: 1
    

    MouseArea
    {
    anchors.fill: parent
    onClicked:
    {
    Qt.createComponent("About_Screen.qml").createObject(root, {});
    }
    }
    }
    }
    @

    Task.qml

    @
    import QtQuick 2.0

    Rectangle
    {
    id: rect
    x:0
    y:0
    width:800
    height:480

    Image {
    id: bg1
    source: "../../resources/images/Home_Screen/Task_Manager/bg.png"
    x: 0
    y: 0
    opacity: 1
    }

    Text {
        id: task_manager
        text: "Task Manager"
        font.pixelSize: 20
        font.family: "Arial-BoldMT"
        font.bold: true
        color: "#8bfcfd"
        smooth: true
        x: 400
        y: 10
        opacity: 1
    }
    

    Text {
    id: processText
    x:150
    y:120
    text: "RUNNING"
    font.pixelSize: 18
    font.family: "SegoeUI"
    color: "#8bfcfd"
    smooth: true
    opacity: 1

    }

    Text {
    x:400
    y:120
    text: "CPU"
    font.pixelSize: 18
    font.family: "SegoeUI"
    color: "#8bfcfd"
    smooth: true
    opacity: 1

    }

    Text {
    id: memText
    x:620
    y:120
    text: "MEMORY"
    font.pixelSize: 18
    font.family: "SegoeUI"
    color: "#8bfcfd"
    smooth: true
    opacity: 1

    }

    Image {
    id: refresh
    source: "../../resources/images/Home_Screen/Task_Manager/refresh.png"
    x: 274
    y: 414
    opacity: 1
    MouseArea
    {
    anchors.fill: parent
    onClicked:
    {
    console.log("refresh ... ");

    }
    }
    }

    Image {
        id: end
        source: "../../resources/images/Home_Screen/Task_Manager/end.png"
        x: 452
        y: 414
        opacity: 1
    

    MouseArea
    {
    anchors.fill: parent
    onClicked:
    {
    console.log("end the process ");

    }
    }
    }
    }
    @

    Kindly help me to fix this.

    Thanks & Regards,
    Narayanan K


Log in to reply
 

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