C++ over Qt:控制标签和按钮的透明度

C++ over Qt : Controlling transparency of Labels and Buttons(C++ over Qt:控制标签和按钮的透明度)
本文介绍了C++ over Qt:控制标签和按钮的透明度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

好吧,我再次尝试使用 Qt Creator 上的 Linux GUI 应用程序,我在我的项目的 Qt 资源文件中添加了几个图像.我试图在我的主窗口和其他窗口和对话框中拥有一个漂亮的背景.我使用的是样式表选项(无编码).

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 Creator 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 ???
!I am attaching a snap of how my application looks.

推荐答案

可以通过设置样式表来设置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); 添加到小部件的 styleSheet 属性中.

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:控制标签和按钮的透明度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

相关文档推荐

Unable to access non-const member functions of objects in C++ std::set(无法访问 C++ std::set 中对象的非常量成员函数)
Constructing std::function argument from lambda(从 lambda 构造 std::function 参数)
STL BigInt class implementation(STL BigInt 类实现)
Sync is unreliable using std::atomic and std::condition_variable(使用 std::atomic 和 std::condition_variable 同步不可靠)
Move list element to the end in STL(在 STL 中将列表元素移动到末尾)
Why is overloading operatoramp;() prohibited for classes stored in STL containers?(为什么禁止对存储在 STL 容器中的类重载 operatoramp;()?)