Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. GIF image as background for QListWidget
Forum Updated to NodeBB v4.3 + New Features

GIF image as background for QListWidget

Scheduled Pinned Locked Moved Solved General and Desktop
qlistwidgetbackgroundgif
6 Posts 2 Posters 6.7k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Rohith
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • RatzzR Offline
      RatzzR Offline
      Ratzz
      wrote on last edited by Ratzz
      #2

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

      --Alles ist gut.

      1 Reply Last reply
      1
      • R Offline
        R Offline
        Rohith
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • RatzzR Offline
          RatzzR Offline
          Ratzz
          wrote on last edited by Ratzz
          #4

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

          --Alles ist gut.

          R 1 Reply Last reply
          1
          • RatzzR Ratzz

            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();
            R Offline
            R Offline
            Rohith
            wrote on last edited by
            #5

            @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

            1 Reply Last reply
            0
            • R Offline
              R Offline
              Rohith
              wrote on last edited by
              #6

              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();
              
              1 Reply Last reply
              1

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved