7

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.

Nejat
  • 31,784
  • 12
  • 106
  • 138
RicoRicochet
  • 2,249
  • 9
  • 28
  • 53

4 Answers4

10

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);");
Nejat
  • 31,784
  • 12
  • 106
  • 138
  • sorry but it really is not making any change to how the application is looking. i guess it is not working. – RicoRicochet May 31 '14 at 08:32
  • It's so weird. It works for me. It's just a simple stylesheet which sets alpha to zero causing the widget to be transparent. – Nejat May 31 '14 at 09:10
  • yup, i read about it in the docs also, but surprisingly nothing happens in my program. looking for some other solutions using a QLabel as a background. lets see. – RicoRicochet May 31 '14 at 10:24
5

There is the property "Window opacity" in the QWidget section of the ui element property (bottom right in qtDesigner view). By default it is 1.0 (completely opaque).

It is also available programmatically

UmNyobe
  • 22,539
  • 9
  • 61
  • 90
  • 1
    Window opacity is just available for QDialog or QMainWindow in designer. – Nejat May 30 '14 at 08:00
  • 1
    But the OP wants something for child widgets like QPushbutton or QLabel. Also he wants to do it in designer. The property is not available in designer except for dialogs and windows. – Nejat May 30 '14 at 08:56
  • 1
    You are right. A precision is that it is displayed only for the top level widget (not only QDialog or QMainWindow). But I fail to see why you want only one button to be transparent. – UmNyobe May 30 '14 at 08:56
  • 1
    well, it seems there is no "Window opacity" option in the QWidget section.. I am using QT creator on linux.. – RicoRicochet May 31 '14 at 04:24
  • 1
    I need the buttons to be opaque. In the above picture as you can see the button has become RED also (like the background) this I want to avoid. I want the button to be opaque - white (like a regular button). – RicoRicochet May 31 '14 at 04:27
5

Not from GUI, but still can be useful for someone:

    auto effect = new QGraphicsOpacityEffect(this);
    effect->setOpacity(0.5);
    yourWidget->setGraphicsEffect(effect);
    yourWidget->setAutoFillBackground(true);

Stolen from here.

PolyGlot
  • 740
  • 6
  • 11
1

This worked For me:

this->setWindowOpacity(0.35);
this->setAttribute(Qt::WA_TranslucentBackground, false);
this->setStyleSheet("background-color: yellow;");
Achrome
  • 7,773
  • 14
  • 36
  • 45
osvaldozav
  • 11
  • 1