2

I have a QLabel, and I put an image on it using setpixmap(). That image has alpha channel.

The QLabel is on a QWidget which has a border-image specified by an image (so that the image is rescaled to fill the QWidget).

On the transparent parts of the QLabel, the result is not the image specified on the QWidget, but a gray color characteristic of "no color" Widget.

My question is how do I make this in such a way that the transparent part of the QLabel shows the border-image of the QWidget?

I've tried canceling autofillbackground, changing the background color of the QLabel to white transparent, but none helped.

Jorge Leitao
  • 19,085
  • 19
  • 85
  • 121
  • Not sure if that matters, but what type of image are you using (png, jpeg,?)? – Mat May 27 '12 at 13:39
  • png, I'm sure it has alpha channel – Jorge Leitao May 27 '12 at 14:35
  • Can you show a minimal example that reproduces your problem? – Mat May 27 '12 at 14:36
  • Please show _how_ you create that "background" widget, _how_ you set its border, how you create your label & how you "insert" it into that background widget. It's all a matter of detail, I have no problem with transparent QImages in QLabels. – Mat May 27 '12 at 15:12
  • (sorry on the comment I hit enter to new line, and it posted it. While doing a minimal example I think I found the problem. So, I was styling the QWidget root (the one on the top of the tree) and apparently the root widget does not receive the stylesheet. If I put a QFrame on it, it already receives. Is this possible? – Jorge Leitao May 27 '12 at 15:19

1 Answers1

0

You need to set the Widget Attributes and Window Flags appropriately:

Using QWidget::setAttribute() and Qt::WidgetAttribute...

Qt::WA_TranslucentBackground needs to be set to true.

Along with learning the Window Flags Example should help a lot.

If you are just looking for a single widget that paints a frameless image...

Here is a perfect example:

QSplashScreen Replacement

phyatt
  • 18,472
  • 5
  • 61
  • 80