C ++ over Qt: control transparency of labels and buttons

Well, I tried again to use the Linux GUI application in Qt Creator, I added a couple of images to the Qt resource file of my project. And I tried to have a good background in my main window and other windows and dialogs. I used stylesheets from the option (without coding).

I can’t set the transparency level of labels and buttons. Any ideas on how to do this from the creator of the Qt GUI ???
! I am attached to how my application looks.

+7
c ++ user-interface stylesheet qt qt-designer
source share
3 answers

You can set the 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); in the styleSheet property of the widget in the constructor.

The fourth parameter is alpha. You can also have translucent widgets by setting alpha for some value greater than zero:

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

In the QWidget section of the ui element properties, there is the Window Transparency property (lower right in the qtDesigner view). The default is 1.0 (completely opaque).

It is also available programmatically.

+5
source share

This worked for me:

 this->setWindowOpacity(0.35); this->setAttribute(Qt::WA_TranslucentBackground, false); this->setStyleSheet("background-color: yellow;"); 
+1
source share

All Articles