PDA

View Full Version : QPushButton Icon opacity/transparency



vladozar
25th November 2012, 06:47
Hi,

Im my program, I have a QPushButton button with an Icon and no text. Everything is designed in Qt-Designer. The button is a child of QWidget widgetChild which is a child of a parent QWidget widgetParent.

I can set opacity to widgetParent and all its child widget/buttons/etc with inherit opacity.
But when I set window opacity of the widgetChild, there is no effect at all. Is there a simple way to overide parent opacity for child opacity (not only the background, but containing Icons)?
I do not need to change the opacity of the widgetParent.
What I need help on, is to set opacity/transparency to the widgetChild or button. I have read quit a few posting here on the forum, but most deal with button background, but none seam to help with the Icon in the button.

Eventually I will have 3or4 button in a widget or come other container and all these buttons need to be semi-transparent have semi-opacity. And the need to be in some container, is that at time all buttons will need to be setVesible(false) or setVisible(true).

hope my question and situation is clear.

d_stranz
25th November 2012, 17:01
I think you will need to design your icons with an alpha channel. That is how Qt controls transparency. So when you want your button's icon to be transparent, you will either have to change the alpha for the icon or load a new icon with the correct alpha.

vladozar
26th November 2012, 16:45
Thanks for a quick reply. I have already looked into creating semi-transparent icons for buttons and using that.

Here is what I have done so far. (see attched image) 8461

I have created QWidget subclass "ControlButtons" with window opacity set to .3, and when running this widget by itself it semi-transparent. All objects in this widget are transparent including buttons and button icons. But when adding this subclass widget into a parent widget, all opacity settings are lost.

ControlButtons *cb = new ControlButtons(this);
cb->setGeometry(10,10,cb->width(),cb->height());
Is there a way to set opacity to child widget and leave parent widget opacity by default?