C++ over Qt : Controlling transparency of Labels and Buttons

RicoRicochet picture RicoRicochet · May 30, 2014 · Viewed 15.3k times · Source

Well, I was again trying my hands on a Linux GUI app on Qt Creator, I added couple of images in a Qt resource file of my project. And I tried to have a nice background in my main window and other windows and dialogs. I was using from the stylesheets option (no coding).

I am unable to set the transparency level of labels and pushbuttons. Any ideas on how to do it from Qt creator GUI itself ???
!I am attaching a snap of how my application looks.

Answer

Nejat picture Nejat · May 30, 2014

You can set transparency of QLabel or QPushbutton by setting the stylesheet :

ui->label->setStyleSheet("background-color: rgba(255, 255, 255, 0);");
ui->button->setStyleSheet("background-color: rgba(255, 255, 255, 0);");

You can also add background-color: rgba(255, 255, 255, 0); to the styleSheet property of the widget in the designer.

The fourth parameter is alpha. You can also have semi-transparent widgets by setting alpha to some value more than zero :

ui->button->setStyleSheet("background-color: rgba(255, 255, 255, 50);");