0

I'm developing a BlackBerry 10 mobile application using the Momentics IDE (native SDK).

All I want is to set a label color in c++ with an hex value using the TextStyleDefinition class like below :

Label* titleLabel = container->findChild<Label*>("titleLabelObj");

TextStyleDefinition* TSD;
TSD->setColor(Color::fromARGB("#F01E21"));

titleLabel->textStyle()->setBase(TSD()->style());

The problem is that the 'fromARGB(int argb)' fuction reclaim an int value so I tried to replace "#" by "0x" but it doesn't work.

Can any one help me on this ? I will be very thankfull .

Mohamed Jihed Jaouadi
  • 1,427
  • 4
  • 25
  • 44

2 Answers2

1

Color::fromARGB() expects an integer, not a string...

Try that:

#include <cstdlib>
#include <iostream>
using namespace std;

int hexToInt(string s)
{
    char * p;
    if (s[0]=='#') s.replace(0,1,"");
    return (int)strtol(s.c_str(), &p, 16);
}

then

m_TSD->setColor(Color::fromARGB(hexToInt("#F01E21")));
DirkMausF
  • 715
  • 5
  • 14
  • It works when it is a question of parsing and the returned value is an int kind like 1234567 but when it is used in fromARGB() function it does nothing and the label will be invisible and in the compilator doesn't show anything. – J.M.J 27 mins ago – Mohamed Jihed Jaouadi Apr 15 '15 at 16:11
0

Actually it was simple, you just need to precise the alpha ;

// Let's take for example the hex color below :
QString color = "#F01E21"

// We need to convert string to int after we replace the "#" with "0x"
bool ok;
int stringColorToInt = color.replace("#", "0xFF").toUInt(&ok, 16) // The 'FF' is alpha

// We set the color
TSD->setColor(Color::fromARGB(stringColorToInt));
Mohamed Jihed Jaouadi
  • 1,427
  • 4
  • 25
  • 44