Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Trusted Contributor
Brennan12325
Posts: 204
Registered: ‎05-15-2012
My Device: None
My Carrier: Telus
Accepted Solution

Changing the color of an already rendered label

Is this possible? The TextStyle definition of AbstractTextControl is read-only. The label doesn't seem to have any method of repainting.

 

Right now I'm creating two identical labels, and hiding one initially, then when I "change the color of the label" I hide my visible label and set my invisible one as visible. I think rendering two labels is probably unnecessarily expensive (even though it does solve the problem). Can anyone think of a better way to do it?

----------------------
Check out my app, Alien Flow for reddit

And of course, like my post if you found it helpful or informative!
Please use plain text.
Developer
Developer
lew
Posts: 174
Registered: ‎03-05-2009
My Device: Dev Alpha
My Carrier: -

Re: Changing the color of an already rendered label

read-only meaning you cannot change its reference but the object is still mutable i.e its internal properties can still be modified:

 

Label {
 id: labelField
 textStyle.color: Color.White
}
...
labelField.textStyle.color = Color.Red

 so you can access the textStyle property directly to modify its properties.

Please use plain text.
Trusted Contributor
Brennan12325
Posts: 204
Registered: ‎05-15-2012
My Device: None
My Carrier: Telus

Re: Changing the color of an already rendered label

How would you do this in C++? Attempting to change the label color by accessing the TextStyle wasn't working, but I think I may have been accessing it in an incorrect manner.

 

Maybe I'll play around with it a little more if it's that simple. Usually things are just as easy in C++ as QML.

----------------------
Check out my app, Alien Flow for reddit

And of course, like my post if you found it helpful or informative!
Please use plain text.
Developer
oliver_kranz
Posts: 216
Registered: ‎09-18-2009
My Device: Z10
My Carrier: O2

Re: Changing the color of an already rendered label

You can inherit from Label. Then you can call Label.textStyle() which returns a pointer to the bb::cascades::TextStyleDefinition. Then you can invoke setColor() to set the color. This should work. I have never done this but the UI components update automatically even when changed in C++.

Please use plain text.