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 Answers
You can use the attribute
widget->setAttribute(Qt::WA_NoSystemBackground);
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.
It is all well-explained in QWidget documentation: http://doc.qt.io/qt-5/qwidget.html#transparency-and-double-buffering
-
3both links are dead, which is the reason why answers should not just contain links but the relevant information itself.– hochlAug 19, 2015 at 9:19
-
I agree that is a problem. However the information asked for here is not very specific and the documentation is explaining it very well. No need to repeat it here. I updated the link to the documentation.– ypnosAug 19, 2015 at 15:33
-
1The explanation does not really help or work, though. I added a QGraphicsView to a transparent widget, but despite setting the graphics view's Qt::WA_PaintOnScreen attribute, it remains to appear as transparent as the widget it is in. Oct 11, 2016 at 6:53