C ++ over Qt:控制标签和按钮的透明度 [英] C++ over Qt : Controlling transparency of Labels and Buttons
问题描述
好吧,我再次尝试我的手在Qt Creator上的一个Linux GUI应用程序,我添加了几个图像在我的项目的Qt资源文件。我试图在我的主窗口和其他窗口和对话框中有一个很好的背景。我正在使用stylesheets选项(无编码)。
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).
我无法设置标签和按钮的透明度级别。任何想法如何做它从Qt创建者GUI本身?
>
I am unable to set the transparency level of labels and pushbuttons. Any ideas on how to do it from Qt creator GUI itself ???
推荐答案
您可以通过设置样式表设置QLabel或QPushbutton的透明度:
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);");
您也可以添加 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.
第四个参数是alpha。您还可以通过将alpha设置为大于零的某个值来实现半透明小部件:
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);");
这篇关于C ++ over Qt:控制标签和按钮的透明度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!