Remove QListView background

前端 未结 2 1141
挽巷
挽巷 2021-01-21 07:36

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

2条回答
  •  日久生厌
    2021-01-21 07:46

    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.

提交回复
热议问题