Vincent
Vincent

Reputation: 60481

QWidget transparent background (but not the children)

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?

Upvotes: 3

Views: 13590

Answers (2)

MSA
MSA

Reputation: 158

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.

Upvotes: 4

ypnos
ypnos

Reputation: 52397

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

Upvotes: 1

Related Questions