Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Qml dynamic component creation - Mouse Events
Forum Updated to NodeBB v4.3 + New Features

Qml dynamic component creation - Mouse Events

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 1.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    narayanan.krish
    wrote on last edited by
    #1

    Hi,

    The following are my qml codes. I am creating the task component on a mouse click on main.qml.
    I have an issue regarding the mouseEvents.
    When I make any mouse click on Taks.qml (dynamically created component), the mouse event from Task.qml passes to main.qml.
    Kindly help me to fix this.

    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 ");

    }
    }
    }
    }
    @

    Thanks & Regards,
    Narayanan K

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      try enabled:false in inside the onClicked handler in main.qml.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved