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
Contributor
Posts: 14
Registered: ‎11-07-2013
My Device: x
My Carrier: y
Accepted Solution

TextStyle.color ignored when modified from C++

Setting textStyle.color from QML works just fine. Although, when I try to create controls in C++ and add them dynamically to a container created in QML, the textStyle.color gets ignored every time.

 

Label* lbl= new Label();
QString text("SomeText");
 
lbl->textStyle()->setColor(QColor("#000000"));
 
//QColor color = QColor::fromRgb(255, 0, 0);
//QVariant variant = color;
//lbl->textStyle()->setColor(variant);
 
lbl->setText(text);
 
container->add(lbl);

 container is a bb::cascades::Container instantiated from QML.

Developer
Posts: 1,523
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: TextStyle.color ignored when modified from C++

Hi,

I haven't tried calling setColor directly, but the following works:

bb::cascades::TextStyle bodyTextStyle(SystemDefaults::TextStyles::bodyText());
bodyTextStyle.setColor(Color::fromARGB(0xff5a595a));

label->setTextStyle(bodyTextStyle);

Could you try if Color::fromARGB(0xaarrggbb) variant works?

 

 

 


Andrey Fidrya, @zmeyc on twitter
Contributor
Posts: 14
Registered: ‎11-07-2013
My Device: x
My Carrier: y

Re: TextStyle.color ignored when modified from C++

Yep, it works. Although, there is no setTextStyle on label, but I've set it through the Builder.

Label::create().textStyle(bodyTextStyle);

 And yes, 

lbl->textStyle()->setColor(Color::fromARGB(0xffaa1612));

 works as well. The difference is that I've been using the QColor, not Color. Thanks!