How to Convert Qcolor value to hex value?

vettipayyan picture vettipayyan · Jan 6, 2011 · Viewed 25.7k times · Source

I have implemented a QColor dialog box which opens on certain condition. To get the selected color after final selection I use the method selectedColor() which returns the value in QColor. When I print that value, it's like this:

<PyQt4.QtGui.QColor object at 0x01DD7880>

I want color value in hex value like this: #DFDFDF (for grey). If it's not hex, correct me.

Is there any function to convert that?

Any suggestions welcome.

Answer

Jason B picture Jason B · Jan 7, 2011

You need to print selectedColor().name() to print the actual color value in hex. See the QColor Documentation