lazexe
lazexe

Reputation: 369

Qt QColor get color code like 45653 (0-65535)

I have a simple problem but I can't solve it yet.

I hame something like this:

QColor someColor = getColor();

After this I need to get color code that in range (0-65535), I pay your attention that I don't need color codes in range (0-255).

So what I must to do? Maybe something like:

someColor.get...()

Upvotes: 0

Views: 1889

Answers (2)

evolix
evolix

Reputation: 11

Qt already provides such function. See documentation here and here.

What it says:

QRgb QColor::rgb() const
// Returns the RGB value of the color. The alpha value is opaque.

QRgb QColor::rgba() const
// Returns the RGB value of the color, including its alpha.

typedef QRgb
// An ARGB quadruplet on the format #AARRGGBB, equivalent to an unsigned int.
// The type also holds a value for the alpha-channel.

Upvotes: 1

Quim
Quim

Reputation: 66

QColor is a combination of 3 bytes (RGB), so you should be looking for a color range from 0 to 2^24-1 [0, 16777215]

You could do something like:

bool ok;
qDebug() << someColor.name().replace("#", "").toUInt(&ok,16);

Regards.

Upvotes: 1

Related Questions