[英]QWidget background transparent
I have a widget in the main window, the widget has the following styles: 我在主窗口中有一个小部件,该小部件具有以下样式:
background-color:#ffeeeeee;width:100%;height:100%;
It is set-up to widget layout and controls auto size to fill the geometry of the widget, but the background of the widget is always transparent. 它设置为小部件布局并控制自动大小以填充小部件的几何形状,但是小部件的背景始终是透明的。 What can I do to make it opaque?
我该怎么做使其不透明?
This is using Qt5.6 running on RedHat Linux 7.2 这使用在RedHat Linux 7.2上运行的Qt5.6
NOTE: The syntax #ffeeeeee is specific to Qt, where the first node is the alpha, then red, green and blue octets. 注意:语法#ffeeeeee特定于Qt,其中第一个节点是alpha,然后是红色,绿色和蓝色八位字节。
You have too many characters in your color. 您的颜色字符过多。 Change:
更改:
background-color: #ffeeeeee;
to: 至:
background-color: #eeeeee;
If you want to use transparency, you'll have to be explicit: 如果要使用透明度,则必须明确:
background-color: rgba(...);
With the background-color present and set to any of the following: 存在背景色并将其设置为以下任意一项:
background-color:white;width:100%;height:100%;
or 要么
background-color:#ffffff;width:100%;height:100%;
or my original: 或我的原件:
background-color:#ffeeeeee;width:100%;height:100%;
The property, autoFillBackground is set to false and the background of the widget is transparent at run-time. 属性autoFillBackground设置为false,并且小部件的背景在运行时是透明的。
However removing any background-color style and leaving the style as just: 但是,删除任何背景色样式并将样式保留为:
width:100%;height:100%
The property, autoFillBackground is set to true and the widget is opaque. 将属性autoFillBackground设置为true,并且该小部件是不透明的。
As far as I can see there is no error in the styles, I believe this may be an error in Qt. 据我所知,样式没有错误,我相信这可能是Qt中的错误。
Have you tried using QWidget::setWindowOpacity(1) where 1 = opaque and 0 = transperant. 您是否尝试过使用QWidget :: setWindowOpacity(1),其中1 =不透明,0 =透明。
Also try QGraphicsOpacityEffect.The following is code for setting the 50 percent opacity for a pushbutton but It can be extended to a widget as well. 也可以尝试QGraphicsOpacityEffect。以下是用于设置按钮的50%不透明度的代码,但它也可以扩展到小部件。
ui->setupUi(this);
QGraphicsOpacityEffect * effect = new QGraphicsOpacityEffect(ui->pushButton);
effect->setOpacity(0.5);
ui->pushButton->setGraphicsEffect(effect);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.