是否可以设置 qt 小部件的不透明度?
我知道有一个函数 QWidget::setWindowOpacity(qreal level)
但正如文档中所写,它仅适用于 Windows。
有没有办法使布局内的小部件也变得不透明?
我想做的是一个小部件淡入的动画。我曾经用一个首选项对话框做到了这一点,并且它起作用了。
那么您认为有一种方法或解决方法可以实现布局内小部件的不透明度吗?你会怎么做?
提前致谢!
I know that there is a function QWidget::setWindowOpacity(qreal level)
but as written in the documentation this does only work for windows.
Is there a way to make widgets that are lying inside layouts opaque too?
What I'm trying to do is an animation where widgets are fading in. I once did that with a preferences-dialog and there it worked.
So do you think there is a way or a work-around to achieve opacity for widgets inside layouts? How would you do that?
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
只需使用 QGraphicsOpacityEffect 即可实现此效果。
Just use QGraphicsOpacityEffect in order to achieve this effect.
对于 mainwidow 内的小部件来说,默认情况下似乎有
setAutoFillBackground(False)
。要使其淡入淡出,您需要使用
QGraphicsOpacityEffect
以及setAutoFillBackground(True)
一个小示例:在主窗口内调用的小部件内写入
Well for widgets inside mainwidow appear to have
setAutoFillBackground(False)
by default.to make it fade in fadeout u need to to use
QGraphicsOpacityEffect
along withsetAutoFillBackground(True)
a small example: write inside the widget which is called inside the mainwindow
SetWindowOpacity
在 Linux 中对我有用。我使用这样的代码来更改窗口不透明度(值从 0 到 100):SetWindowOpacity
works for me in Linux. I used code like this to change window opacity, (value is from 0 to 100):为我工作
works for me
在 Qt5 中,您可以使用 css 使小部件透明
In Qt5 you can use css to make widgets transparent