问题
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?
回答1:
It is all well-explained in QWidget documentation: http://doc.qt.io/qt-5/qwidget.html#transparency-and-double-buffering
回答2:
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.
来源:https://stackoverflow.com/questions/11688750/qwidget-transparent-background-but-not-the-children