Background for images with alpha channel
-
@QMovie movie = new QMovie (file->absoluteFilePath());
if (!movie->isValid()) {
qDebug()<<tr("Could not open %1 image").arg(file->absoluteFilePath());
return;
}movie->start();
imageLabel->setMovie(movie);
imageLabel->resize(movie->scaledSize());@that's the code.
how do you suggest i use QPainter?
-
So, I think Vass meant to overwrite "paintEvent":http://doc.qt.nokia.com/4.7/qwidget.html#paintEvent and do the painting by yourselve instead of let QImageLabel do the painting for you.
-
This code makes the background red. It's important to call setAutoFillBackground(true) on the label, otherwise the background will not be changed!
@
QPalette pal = ui->label->palette();
pal.setBrush(QPalette::Window, Qt::red);
ui->label->setPalette(pal);
ui->label->setAutoFillBackground(true);
@ -
bq. 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:
@
void myWidgetClass::paintEvent(QPaintEvent*)
{
QPainter paint(this);
painter.draw... // draw the background here
paint.drawImage(rect(), myMove.currentImage());
}
@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?
-
nop, the palette stuff didn't work, when i call setMovie the background is gone, and even calling setBackgroundColor from QMovie doesn't work, so i've done something that fixes my problem, but in a way that isn't the better i guess.
@void ImageViewer::setGifImage()
{
QPixmap m = scuareBackground();
//m is an square 32x32, wich is the base for the alpha background.QPixmap temp(gifSize);
//create a pixmap qith the same size that the gif imageQPainter q(&temp);
q.drawTiledPixmap(0,0,gifSize.width(), gifSize.height(), m);
q.drawPixmap(0, 0, movie->currentPixmap());
q.end();imageLabel->setPixmap(temp);
}
@that's an slot i've made, and it's used in here:
@gifSize=(QPixmap(archivo->absoluteFilePath()).size());
movie->start();
connect(movie, SIGNAL(frameChanged(int)), this, SLOT(setGifImage()));//imageLabel->setMovie(movie);
imageLabel->resize(gifSize);@of course i have to make a lot of improvements but it's something.
if you have something to add or correct do it please
-
If you go that way, I would suggest using the paintEvent, as you are creating a temporary image for each changed frame. Then you cans also derive the label (or from QWidget diretly) and implement thepaint event. Then connect the signal with update and it should work with less temporary objects / images.
@
{
...
gifSize=(QPixmap(archivo->absoluteFilePath()).size());movie->start(); connect(movie, SIGNAL(frameChanged(int)), pImageLabel, SLOT(update())); //imageLabel->setMovie(movie); imageLabel->resize(gifSize); ...
}
void CMyImageLabel::CMyImageLabel(QPixmap backSquare) :
m_squareBackground(backSquare)
{
}void CMyImageLabel::paintEvent()
{
QPainter paint(this);
paint.drawTiledPixmap(rect(), m_squareBackground);
paint.drawImage(rect(), myMove.currentImage());
}
@