开发者

Remove QListView background

开发者 https://www.devze.com 2023-03-27 08:40 出处:网络
I want to remove the background of my QListView so that the background below can be seen through. How can I do that?

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 开发者_如何学PythonpaintEvent() otherwise it doesn't draw the items.

Any idea?


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:

viewport()->setAutoFillBackground( false );

and depending on other setting (i.e. parent widget settings) You should see background.


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:

view->setWindowOpacity(50);

For a widget that's not top level, you want to set the background to one with an alpha channel:

QPalette palette = view->palette();
palette.setColor(QPalette::Background, Qt::transparent);
view->setPalette(palette);

You should also be able to do the same thing with style sheets:

view->setStyleSheet("background-color: transparent;");

You may need to set autoFillBackground to false so that the widget will not automatically fill in the background.

0

精彩评论

暂无评论...
验证码 换一张
取 消