3

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 2

4

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.

0
1

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

3
  • 3
    both links are dead, which is the reason why answers should not just contain links but the relevant information itself.
    – hochl
    Aug 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.
    – ypnos
    Aug 19, 2015 at 15:33
  • 1
    The 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, 2016 at 6:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.