Results 1 to 4 of 4

Thread: Change Opacity of QPushButton

  1. #1
    Join Date
    Apr 2009
    Posts
    63
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    Windows

    Default Change Opacity of QPushButton

    I have a QPushButton in my application and I simply want to change the opacity (i.e. alpha) of it. What is the best way to do this?

  2. #2
    Join Date
    Jan 2007
    Posts
    92
    Thanks
    14
    Thanked 1 Time in 1 Post

    Default Re: Change Opacity of QPushButton

    Qt Code:
    1. QPushButton * pushButton = new QPushButton(....);
    2. QPalette palette = pushButton->palette();
    To copy to clipboard, switch view to plain text mode 
    For general background color use QPalette::Window or QPalette::Text

    Qt Code:
    1. QColor color = palette.color(QPalette::Window);
    2. color.setAlpha(130);
    3. palette.setColor(QPalette::Text, color);
    4. pushButton->setPalette(palette);
    To copy to clipboard, switch view to plain text mode 

    There is another way to setup using style sheet
    Qt Code:
    1. QPushButton { color: rgba(0, 0, 0, 50%) }
    To copy to clipboard, switch view to plain text mode 

  3. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Change Opacity of QPushButton

    You can subclass the widget and use QPainter::setOpacity() to make it semi transparent.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Oct 2010
    Posts
    5
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Question Re: Change Opacity of QPushButton

    use this simple code guys it worked for me .....

    ui->male_button->setFlat(TRUE);

    ui->male_button->setStyleSheet("* { background-color: rgba(0,125,0,0) }");

Similar Threads

  1. Change background color of QPushButton
    By gtthang in forum Qt Programming
    Replies: 3
    Last Post: 26th November 2013, 10:23
  2. Change QPushButton Background Color, Qt4.3
    By Rayven in forum Qt Programming
    Replies: 5
    Last Post: 4th July 2009, 07:14
  3. Qpushbutton
    By iamhere in forum Qt Programming
    Replies: 5
    Last Post: 15th October 2008, 04:40
  4. How to change color of a QPushButton?
    By vishal.chauhan in forum Qt Programming
    Replies: 6
    Last Post: 5th March 2008, 13:22
  5. Change background color for a QPushButton?
    By Harvey West in forum Qt Programming
    Replies: 6
    Last Post: 5th January 2007, 14:23

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.