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?
Asked
Active
Viewed 1.3k times
3

NoDataDumpNoContribution
- 10,591
- 9
- 64
- 104

Vincent
- 57,703
- 61
- 205
- 388
2 Answers
4
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.

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

ypnos
- 50,202
- 14
- 95
- 141
-
4both links are dead, which is the reason why answers should not just contain links but the relevant information itself. – hochl Aug 19 '15 at 09: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. – ypnos Aug 19 '15 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. – TheSHEEEP Oct 11 '16 at 06:53