How to make the QLabel background semi-transparent?

前端 未结 1 382
鱼传尺愫
鱼传尺愫 2021-01-11 11:04

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

相关标签:
1条回答
  • 2021-01-11 11:50

    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).

    0 讨论(0)
提交回复
热议问题