Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt + gif + alpha

Tags:

gif

alpha

qt

How to make a transparent background in QLabel with QMovie? Gif already has set transparency. I need to do something like KamikadzeCat or Felix. It's cats, that do something on Homescreen. I tried to write:

QLabel lb;
QMovie mv1("ooo.gif");
lb.setMovie(&mv1);
mv1.start();
lb.setWindowFlags(Qt::FramelessWindowHint);
lb.show();

Also I tryed to write:

lb.setStyleSheet("background-color: rgba(225,255,255,0);");

Bur it's not working at all. if first time the label was with gray background, and in the second time I tried to write a lot of numbers in rgba, but it was useless.

like image 894
user2328479 Avatar asked Apr 29 '13 12:04

user2328479


People also ask

Can GIFs have alpha channels?

GIF doesn't have an alpha channel like PNG, so you can't get smooth transparent edges. The alpha channel specifies how transparent each pixel is, so you could have half-transparent pixels for example. GIF on the other hand is limited to 8 bit colors and one of them is designated as the transparent color.

Does GIF support alpha transparency?

Unfortunately no, the GIF format doesn't support partial (alpha-channel) transparency, meaning any pixel can only be fully tansparent or fully opaque, so it's not possible to make partially transparent GIFs and achieve anti-aliasing effect against different backgrounds.


1 Answers

You can set the Qt::WA_TranslucentBackground attribute to your QLabel to get a translucent background:

yourLabel->setAttribute( Qt::WA_TranslucentBackground, true );
like image 127
Dimitry Ernot Avatar answered Nov 15 '22 09:11

Dimitry Ernot