How To change the background color of a container

2019-08-05 22:03发布

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

I want to change the background color of a container using C++. But unfortunately, relating to this [link], you only can define it like below :

**Creating a color in C++:**
Color c1 = Color::fromRGBA(0.5f, 1.0f, 0.2f, 0.8f);
Color c2 = Color::fromARGB(0xff996633);

For the color, I want to use the hex format ("#xxxxxx"). Any one can guide me on this ?

1条回答
Viruses.
2楼-- · 2019-08-05 22:30

Color c2 = Color::fromARGB(0xff996633); is using hex the 0x is c++ representation of a hex code. ff is the A component, 99 is the R, 66 is the G and 33 is the B

So if you want to use the hex value #000099 with no alpha

then it would be

Color::fromARGB(0x00000099)

The following code will convert a string to a hex value, you will need to remove the # from the string before hand however, and then can pass the string into the buffer object

#include <iostream>
#include <sstream>

int main() { 

    std::string hexString("#ffffff");
    hexString.erase(hexString.begin());

    std::istringstream buffer(hexString);

    int value;

    buffer >> std::hex >> value;

    std::cout << std::hex << value;
    return 0;
}
查看更多
登录 后发表回答