How to create X11 colors into Qt QColor Wrapper

You can mix any color you want nowadays with 32-bit colors. But sometimes, it’s just so much more convenient if the color palette already exists. And unfortunately, Qt only provides users with the most basic of colors. Therefore, it’s up to you to come up with a snazzy pre-mixed color palette yourself, but also to name those custom colors. But you don’t need to reinvent the wheel. The X Windows system and W3 web standard for colors and names already exists.

Unfortunately, if you’re using Qt on Windows, you won’t be able to access that color palette.

So this is what I did: I simply took the names and RGB values and created a wrapper class in Qt. That way I can easily access the colors via their names. Ain’t that a trip? It seems so simple to implement, but I haven’t found any tutorials out there on the Interwebs. It could save a lot of time for those that deal with a lot of colors.

Also, I whipped up a quick demo that displays the colors all nice and purdy.

X11 colors as QColor in Qt 4.8.5
X11 colors as QColor in Qt 4.8.5

Feel free to use this X11 color name wrapper class in your Qt project. Enjoy!

You can download the Qt 4.8.5 project files here: