QWidget transparent background (but not the childr

2019-08-01 19:29发布

I have a QWidget that contains a QPixmap and a QComboxBox in its Layout. I would like to set the background of the widget transparent (but I want to show the QPixmap and the QComboBox normally). How do I do that?

2条回答
欢心
2楼-- · 2019-08-01 19:46

It is all well-explained in QWidget documentation: http://doc.qt.io/qt-5/qwidget.html#transparency-and-double-buffering

查看更多
趁早两清
3楼-- · 2019-08-01 19:48

You can use the attribute

widget->setAttribute(Qt::WA_NoSystemBackground);

Qt documentation :

Indicates that the widget has no background, i.e. when the widget receives paint events, the background is not automatically repainted. Note: Unlike WA_OpaquePaintEvent, newly exposed areas are never filled with the background (e.g., after showing a window for the first time the user can see "through" it until the application processes the paint events). This flag is set or cleared by the widget's author.

查看更多
登录 后发表回答