Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. QT 5.9.4 - problems changing Label or Text color programmatically
Forum Updated to NodeBB v4.3 + New Features

QT 5.9.4 - problems changing Label or Text color programmatically

Scheduled Pinned Locked Moved Unsolved Mobile and Embedded
1 Posts 1 Posters 127 Views
  • 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.
  • F Offline
    F Offline
    Forcecode
    wrote on 22 Sept 2023, 19:49 last edited by Forcecode
    #1

    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?

    1 Reply Last reply
    0

    1/1

    22 Sept 2023, 19:49

    • Login

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