我试图添加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播放。
答案 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();
我试过这对我有用..!