GIF image as background for QListWidget



  • Hi,

    I want to set GIF image as an background image for the QListWidget , is it possible to do so.
    If it is possible please tell me the piece of code that helps me to execute.

    Thanks in advance,
    Rohith.G



  • You can use setStyleSheet

    ui->listWidget->setStyleSheet("background-image: url(Path/to/gif.gif)");
    

    or

     ui->listWidget->setStyleSheet(QString("QListWidget { background-image: url(Path/to/gif.gif) }"));


  • Hi Ratzz,

    Thanks for replying, actually i have already tried the method which you have said.
    In general we will use the QMovie to load a gif images and to see the actions that were present in the gif image but on using the setStylesheet i was unable to see the actions or animation moving that was present in the gif image i need to see the animation too when i apply the image as a background for QListWidget.

    Thanks in advance,
    Rohith.G



  • Hello
    You can create a QLabel in .ui file over the QListWidget region and then you can use setMovie

        #include <QMovie>
        QMovie *movie = new QMovie("path/to/gif.gif");    
        ui->label->setMovie(movie);
        movie->start();


  • @Ratzz

       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);
    

    I have tried in this manner Ratzz,please correct if there are any mistakes

    Thanks in advance,
    Rohith.G



  • I have added these few lines to resemble GIF image as background for QListWidget

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

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.