Qml dynamic component creation - Mouse Events
-
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 GlobalJSRectangle {
id: root
width:800
height:480Image { 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.0Rectangle
{
id: rect
x:0
y:0
width:800
height:480Image {
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 -
try enabled:false in inside the onClicked handler in main.qml.