QT 5.9.4 - problems changing Label or Text color programmatically
Unsolved
Mobile and Embedded
-
I have a BoxButton.qml defined as follows:
import QtQuick 2.9 import QtQuick.Controls 2.9 import "." Rectangle { property int boxId: 0 property string boxNo: "..." property string boxColor: "#efefef" property string labelColor: "#000000" signal btnClick(int boxId) width: 105 height: 105 radius: 5 color: boxColor Label { id: label anchors.centerIn: parent text: parent.boxNo color: parent.labelColor font.pixelSize: 24 font.family: Fonts.fontRobotoBlackLoader.name } MouseArea { anchors.fill: parent onClicked: { label.color = "#ffffff" btnClick(parent.boxId) } } }
I am using it to create clickable boxes dynamically like so:
Component.onCompleted: { var boxes = DataProvider.fetchBoxes(); var component = Qt.createComponent("BoxButton.qml") if (component.status === Component.Ready) { for (var n=0;n<boxes.length;n++) { var button = component.createObject(boxContainer) button.boxId = boxes[n].id button.boxNo = boxes[n].id if (boxes[n].isSystem) { button.boxColor = "#000000" button.labelColor = "#ffffff" } else { button.boxColor = "#cccccc" } button.onBtnClick.connect(handleBoxButton) } } }
All boxes as created properly. Changing the boxColor property changes the background color of the boxes. The problem is that the same for the labelColor property doesn't work and the text color of the Label is not changing. The boxContainer is just:
Flow { id: boxContainer width: 800 spacing: 20 }
Anyone experienced this strange behaviour?