Results 1 to 3 of 3

Thread: QPushButton Icon opacity/transparency

  1. #1
    Join Date
    Apr 2009
    Posts
    17
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question QPushButton Icon opacity/transparency

    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.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,969
    Thanks
    277
    Thanked 808 Times in 797 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: QPushButton Icon opacity/transparency

    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.

  3. #3
    Join Date
    Apr 2009
    Posts
    17
    Thanks
    7
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Re: QPushButton Icon opacity/transparency

    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) opacity.png

    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.
    Qt Code:
    1. ControlButtons *cb = new ControlButtons(this);
    2. cb->setGeometry(10,10,cb->width(),cb->height());
    To copy to clipboard, switch view to plain text mode 
    Is there a way to set opacity to child widget and leave parent widget opacity by default?

Similar Threads

  1. Replies: 9
    Last Post: 8th November 2011, 15:54
  2. Replies: 3
    Last Post: 8th September 2011, 15:45
  3. Change Opacity of QPushButton
    By DiamonDogX in forum Qt Programming
    Replies: 3
    Last Post: 5th November 2010, 12:09
  4. How stretch icon in QPushButton?
    By cutie.monkey in forum Qt Programming
    Replies: 1
    Last Post: 8th July 2010, 08:54
  5. Tree selection - icon transparency (lack of)
    By MrGarbage in forum Qt Programming
    Replies: 1
    Last Post: 8th January 2008, 21:48

Tags for this Thread

Bookmarks

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.