PDA

View Full Version : Change Opacity of QPushButton



DiamonDogX
9th April 2009, 15:41
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?

user_mail07
9th April 2009, 18:42
QPushButton * pushButton = new QPushButton(....);
QPalette palette = pushButton->palette();

For general background color use QPalette::Window or QPalette::Text


QColor color = palette.color(QPalette::Window);
color.setAlpha(130);
palette.setColor(QPalette::Text, color);
pushButton->setPalette(palette);

There is another way to setup using style sheet

QPushButton { color: rgba(0, 0, 0, 50%) }

wysota
9th April 2009, 22:47
You can subclass the widget and use QPainter::setOpacity() to make it semi transparent.

ragha4u
5th November 2010, 12:09
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) }");