Nominate our 2022 Qt Champions!

Is it possible to set QLabel background color and add transparent image to it?

  • Hi,
    I would like to set QLabel's baground to red. Next I have transparent png image ( circle ). I would like to set this image to label and get red background and a circle on it:


    When I write "transparent png image circle" I think about this:


  • Lifetime Qt Champion


    One way that comes to mind is to overwrite the paintEvent. In it fill the widget with red and then draw the image on top.

  • I am not sure I understand the problem:

    • You can always set pixmap which may have transparent color (created from the image). In this case all you need to change background of the QLabel (for example using stylesheet)
    • Above way is good in most cases, but if your pixmap size is very different from label size, and you really want perfect look and scalability of the button you follow SGaist's suggestion and draw ellipse in the paint event instead using pixmap.

Log in to reply