Quantcast
Channel: Qt DevNet forums: Qt Quick 1283365070**
Viewing all articles
Browse latest Browse all 4972

How to make dynamically created "Rectangle" components to bold one "Rectangle" text and unbold another when clicked?

$
0
0
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 ? :)

Viewing all articles
Browse latest Browse all 4972

Trending Articles