January 4, 2012

dbarrett dbarrett
Lab Rat
2 posts

Icon foreground color modification

 

I have an icon in .png format that is essentially a black symbol with a clear background. I’d like to apply this icon to a QPushButton, but with the color of the black foreground image to be set dynamically (not always black). Is there a good way to do this? I could produce multiple .png files with different colors, but I’d like the dynamic color range of the icon to be more “continuous” if possible.

Thanks in advance!
-Dan

3 replies

January 4, 2012

Volker Volker
Robot Herder
5428 posts

You could try to turn the black pixels into transparent ones and set a background color on the button. This has the drawback that the complete button has that background color. There’s no easy built-in way in Qt to change all pixels of a certain color to another color.

January 5, 2012

dbarrett dbarrett
Lab Rat
2 posts

That would unfortunately result in the entire image being transparent.

If not the ability to change the color of all pixels of a certain color, how about the ability to set the color of all opaque pixels? This would achieve the same result in this case since all opaque pixels are of the same color.

Thanks,
Dan

January 5, 2012

Andre Andre
Area 51 Engineer
6031 posts

Well, you could load the image into a QImage, and loop over the pixels. You can change them one-by-one that way. If the shape is not very complicated, it would perhaps be better to just draw it yourself in the right color in Qt? Or, perhaps you can use Qt SVG capabilities and use that to render the shape in the right color?

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

 
  ‹‹ Segfault In ~QGraphicsItem() Due To Duplicate Transforms      Windows Explorer in Qt Application via QAxWidget ››

You must log in to post a reply. Not a member yet? Register here!