1. Intermediate user
Join Date
Mar 2009
Location
Gansu,China
Posts
188
Qt products
Platforms

## RGB QColor(QRgb)

I want to create a QColor,I find that QColorcan be created by
Qt Code:
`QColor(int r,int g,int b,int a=255)`
To copy to clipboard, switch view to plain text mode
or by
Qt Code:
`QColor(QRgb color)`
To copy to clipboard, switch view to plain text mode
,Now I have two questions:
1.if the value of r,g,b is between 0 and 1,how to convert to int? because
Qt Code:
`QColor(int r,int g,int b,int a=255)`
To copy to clipboard, switch view to plain text mode
need int parameter?
2.If I use
Qt Code:
`QColor(QRgb color)`
To copy to clipboard, switch view to plain text mode
to create a color,how to convert (0,1) to tpye QRgb?
Thk u.

2. ## Re: RGB QColor(QRgb)

there is QRgb qRgba ( int r, int g, int b, int a ), use it.

3. Intermediate user
Join Date
Mar 2009
Location
Gansu,China
Posts
188
Qt products
Platforms

## Re: RGB QColor(QRgb)

QRgb qRgba ( int r, int g, int b, int a ),which needs int parameter,but I have the value of r,g,b is between 0 and 1? How to convert them to int value?
thank u.

Join Date
Dec 2007
Posts
627
Thanks
3
Thanked 89 Times in 87 Posts
Qt products
Platforms

## Re: RGB QColor(QRgb)

You have to manually map the values from.
0..........1

On

0..........255

Then pass the mapped value in qRgba(); I am not good in Mathematics otherwise could have provide you the actual solution.

Join Date
Jul 2009
Location
Enschede, Netherlands
Posts
462
Thanked 69 Times in 67 Posts
Qt products
Platforms

## Re: RGB QColor(QRgb)

If you just want to create a QColor from rgb values between 0 and 1, you can also use QColor::setRgbF(). No need to think about
Qt Code:
`(quint8)(value*255)`
To copy to clipboard, switch view to plain text mode
and polluting your code with it.

6. Intermediate user
Join Date
Mar 2009
Location
Gansu,China
Posts
188
Qt products
Platforms

## Re: RGB QColor(QRgb)

thk u.i wil try.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.