删除QListView背景
我想删除我的 QListView 的背景,以便可以看到下面的背景。我怎样才能做到这一点?
我尝试了 setAttribute(Qt::WA_NoSystemBackground) 和 setAttribute(Qt::WA_NoBackground) 但这并没有改变任何东西。另外,我无法覆盖 paintEvent()
否则它不会绘制项目。
有什么想法吗?
I want to remove the background of my QListView so that the background below can be seen through. How can I do that?
I tried setAttribute(Qt::WA_NoSystemBackground)
and setAttribute(Qt::WA_NoBackground)
but that didn't change anything. Also I cannot override paintEvent()
otherwise it doesn't draw the items.
Any idea?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不要忘记 QScrollArea(QListView 的基类)包含“另一个”小部件,称为 Viewport。可以通过 viewport() 方法访问它。
要实现透明度,您只需调用:
并根据其他设置(即父窗口小部件设置)您应该看到背景。
Don't forget that QScrollArea, which is base class for QListView contains "another" widget which is called Viewport. It can be accesed via viewport() method.
To achieve transparency You can simply just call:
and depending on other setting (i.e. parent widget settings) You should see background.
答案取决于您的 QListView 是否是顶级小部件。 有关透明度的 QWidget 文档 详细解释了这一点。对于顶级小部件,它可能很简单:
对于非顶级小部件,您希望将背景设置为带有 alpha 通道的背景:
您还应该能够使用样式表执行相同的操作
:可能需要将 autoFillBackground 设置为 false,以便小部件不会自动填充背景。
The answer depends on whether your
QListView
is a top-level widget. The QWidget docs on transparency explain in detail. For a top-level widget, it may be as simple as:For a widget that's not top level, you want to set the background to one with an alpha channel:
You should also be able to do the same thing with style sheets:
You may need to set autoFillBackground to false so that the widget will not automatically fill in the background.