如何添加Gif图像作为QListWidget的背景..?

时间:2016-03-21 10:16:49

标签: animated-gif qlistwidget

我试图添加Gif Image作为QListWidget的背景,下面是我试图实现的代码。

myMovie = new QMovie(":/images/icon_gif.gif");
movieLabel = new QLabel(this);
movieLabel->setMovie(myMovie);
myMovie->start();

listWidget = new QListWidget(this);
listWidget->setViewMode(QListView::IconMode);
listWidget->resize(800,600);

QListWidgetItem *sample = new QListWidgetItem();
sample->setIcon(QIcon(":/images/shutdown.png"));
sample->setText("Sample");
sample->setTextAlignment(Qt::AlignHCenter);

listWidget->addItem(sample);
listWidget->setItemWidget(sample,movieLabel);

我希望Gif图像显示为QListWidget的背景,我希望它的动画可以使用QMovie播放。

Here is the OutPut image

1 个答案:

答案 0 :(得分:0)

myMovie = new QMovie(":/images/icon_gif.gif");
movieLabel = new QLabel(this);
ui->label->setMovie(myMovie);
myMovie->start();

QPixmap pix = QPixmap::grabWidget(ui->label,20,30,741,481);
pix.fill(Qt::transparent);
QPalette p;
p.setBrush(QPalette::Base,pix);
p.base();

我试过这对我有用..!