I have created QLabel *msgLbl
. How do I make the msgLbl
background semi-transparent?
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 QLabel
s, 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).