Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make the QLabel background semi-transparent?

Tags:

qt

I have created QLabel *msgLbl. How do I make the msgLbl background semi-transparent?

like image 756
Shyam Avatar asked Oct 28 '11 11:10

Shyam


People also ask

How do I make my background color semi transparent?

The code for a semi-transparent blue background is: background: rgba(30, 52, 142, 0.5); Another technique for increasing the visibility of semi-transparent buttons is to give them a solid-colored border.

How do I make a semi transparent background image in CSS?

To achieve this, use a color value which has an alpha channel—such as rgba. As with opacity , a value of 1 for the alpha channel value makes the color fully opaque. Therefore background-color: rgba(0,0,0,. 5); will set the background color to 50% opacity.

How do I make a semi transparent background in HTML?

use opacity css property. Do you want a semi transparent background color or image? Add this to your CSS background-color:rgba(255,0,0,0.5) . Increase or decrease the 0.5 to lower or raise the opacity.

How do I change the opacity of an image in Qt Designer?

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);");


1 Answers

The easiest way is probably to call setStylesheet(). If you're using Qt Designer you can also set the stylesheet from within the designer window (look in the properties bar on the right.

You want to set the background-color attribute, so something like

msgLbl->setStyleSheet("background-color: rgba(255, 255, 255, 10);");

would be the simplest way to do what you describe.

Having said that, you might also want to think about stylesheet inheritance. For example, you might want to set the background-color for a number of QLabels, all children of a parent widget. You can do that using css-style selectors in a stylesheet set on the parent widget (read this for more information).

like image 57
sam-w Avatar answered Oct 24 '22 18:10

sam-w