Hi,
I want to do when I clicked dynamically created “rectangle” component, that component text goes bold, and then I clicked another component, previous clicked component goes unbold, i tryied different ways to do that, but nothing work.
Here is my “Rectangle” component:
import QtQuick 2.0
Rectangle {
id: btn;
width: 100;
height: 100;
color: "lightblue";
property string btn_text: "";
property string txt_bold;
Text {
id: txt;
anchors.centerIn: parent.Center;
color: "black";
text: btn.btn_text;
font.bold: btn.txt_bold;
}
MouseArea {
id: mouse;
anchors.fill: parent;
onClicked: {
btn.txt_bold = true;
console.log("Clicked " + txt.text );
}
}
}
And my main where i create dynamically components:
import QtQuick 2.0
Rectangle {
id: test;
width: Style.width;
height: Style.height;
color: "#ccc";
Component.onCompleted: {
for(var i = 0; i<5; i++) {
var comp = Qt.createComponent("test_comp.qml");
var object = comp.createObject(test, {"x":50,"y":(10 * i)*i});
object.btn_text = "Button " + i;
object.y = (object.width + 10) * i;
}
}
}
Any idea ? :)
↧