December 19, 2010

samkpo samkpo
Lab Rat
16 posts

background for images with alpha channel

Page  
1

I’m making an image viewer, and i have made it shows animated images, but i can’t find the way to set the background for those that have an alpha channel. It’s easy to make it with static images, using qpainter, but i don’t know how to do it with animated images.

by the way, i’m learning both Qt and english, so please be patient :-P

27 replies

December 19, 2010

Vass Vass
Hobby Entomologist
738 posts

Please, show you code, how you work with QMovie, and I don’t understand you need “Alpha background” as in Title or “background for images with alpha channel” as in topic body? :)

 Signature 


Vasiliy

December 19, 2010

peppe peppe
Ant Farmer
1025 posts

On a side note, QMovie is perfectly paintable with QPainter (you obtain the current frame with currentImage() or currentPixmap()).

 Signature 

Software Engineer
KDAB (UK) Ltd., a KDAB Group company

December 19, 2010

samkpo samkpo
Lab Rat
16 posts

  1. QMovie movie = new QMovie (file->absoluteFilePath());
  2.         if (!movie->isValid()) {
  3.      qDebug()<<tr("Could not open %1 image").arg(file->absoluteFilePath());
  4.      return;
  5.         }
  6.  
  7.  movie->start();
  8.  imageLabel->setMovie(movie);
  9.  imageLabel->resize(movie->scaledSize());

that’s the code.

how do you suggest i use QPainter?

December 19, 2010

Vass Vass
Hobby Entomologist
738 posts

imageLabel has type QLabel, right? QLabel is subclass of QWidget, QWidget is subclass of QPaintDevice.
Use QPainter for imageLabel

 Signature 


Vasiliy

December 19, 2010

Gerolf Gerolf
Area 51 Engineer
3210 posts

So, I think Vass meant to overwrite paintEvent [doc.qt.nokia.com] and do the painting by yourselve instead of let QImageLabel do the painting for you.

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

December 19, 2010

samkpo samkpo
Lab Rat
16 posts

yes, it’s a QLabel Object. Ok, i understand what you say but don’t know how to use QPainter for imageLabel

December 19, 2010

Gerolf Gerolf
Area 51 Engineer
3210 posts

If you do the painting on your own, you overwrite paint event like the following code:

  1. void myWidgetClass::paintEvent(QPaintEvent*)
  2. {
  3.     QPainter paint(this);
  4.     paint.drawImage(rect(), myMove.currentImage());
  5. }

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

December 19, 2010

Vass Vass
Hobby Entomologist
738 posts

Gerolf It seems to me what I with you said about different things. As I understand samkpo has movie with alpha channel, and He want set background under this movie. You said about animate background for something with use Qmovie.

 Signature 


Vasiliy

December 19, 2010

samkpo samkpo
Lab Rat
16 posts

yes, that’s what i want

December 19, 2010

Vass Vass
Hobby Entomologist
738 posts

what exactly?

 Signature 


Vasiliy

December 19, 2010

Gerolf Gerolf
Area 51 Engineer
3210 posts

Ok, sorry, then I misunderstood….

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

December 19, 2010

samkpo samkpo
Lab Rat
16 posts

i have a movie with alpha channel and i want to set a background under this movie

December 19, 2010

Volker Volker
Robot Herder
5428 posts

This code makes the background red. It’s important to call setAutoFillBackground(true) on the label, otherwise the background will not be changed!

  1.     QPalette pal = ui->label->palette();
  2.     pal.setBrush(QPalette::Window, Qt::red);
  3.     ui->label->setPalette(pal);
  4.     ui->label->setAutoFillBackground(true);

December 19, 2010

peppe peppe
Ant Farmer
1025 posts

You need to subclass QLabel (or simply write a new widget from scratch) and in its paintEvent paint the background and then the current QMovie frame; or you can enable autoFillBackground and change the label’s background palette. :)

 Signature 

Software Engineer
KDAB (UK) Ltd., a KDAB Group company

December 19, 2010

Gerolf Gerolf
Area 51 Engineer
3210 posts

Vass wrote
Gerolf It seems to me what I with you said about different things. As I understand samkpo has movie with alpha channel, and He want set background under this movie. You said about animate background for something with use Qmovie.

But then you can just paint the background beffore drawing the move:

  1. void myWidgetClass::paintEvent(QPaintEvent*)
  2. {
  3.     QPainter paint(this);
  4.     painter.draw... // draw the background here
  5.     paint.drawImage(rect(), myMove.currentImage());
  6. }

Or position a label or widget with the needed background exactly below the imageLabel. (so position one widget with setgeometry or make obne label a child of the other one). Or does QLabel not draw the movie with transparent background?

 Signature 

Nokia Certified Qt Specialist.
Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

Page  
1

  ‹‹ Getting a .pro file to work for both Visual Studio 2008 and Qt Creator      How do I "move" an item from one QListWidget to another? ››

You must log in to post a reply. Not a member yet? Register here!