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. How to load gif image in Qlistview
Forum Updated to NodeBB v4.3 + New Features

How to load gif image in Qlistview

Scheduled Pinned Locked Moved General and Desktop
7 Posts 2 Posters 4.3k Views 1 Watching
  • 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.
  • M Offline
    M Offline
    maxy
    wrote on last edited by
    #1

    Hi ,
    I want to load the gif image in qlistview each row.Normally i used QMovie to load the gif image in widget.But How to load the listview each row.

    Kindly help me

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      you still have to use QMovie but it's a bit more tricky.

      You need to listen to QMovie's frameChanged() signal and trigger an update on the QListView using QAbstractItemView::update(const QModelIndex & index )
      In your model return the current frame of QMovie in the data() method for Qt::DecorationRole.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • M Offline
        M Offline
        maxy
        wrote on last edited by
        #3

        Thanks for your reply.Normally I fill the list strings by using custom delegate
        paint method.Now my question is how i use the QMovie inside the paint or custom delegate.?

        How i load the QMovie in row?

        Thanks

        1 Reply Last reply
        0
        • raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          In your custom delegate do you call the base class implementation for painting or do you do the painting of the whole cell by yourself?

          In the first case do as i said with the model and the Qt::DecorationRole. In the second case just paint the current frame of the QMovie yourself.

          If you mean how to handle the QMovies:
          You will need to store them on a central place (e.g. model) with your view. You can use QPersistentModelIndex for mapping the index to the right QMovie object.
          But you need to take care of the cleanup of the list (or whatever storage container you use) and remove the QPersistentModelIndex and it's QMovie object from to avoid "infinite" memory consumption ;)

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • M Offline
            M Offline
            maxy
            wrote on last edited by
            #5

            In paint method i used QPainter for drawText and drawPixmap functions

            Thanks

            1 Reply Last reply
            0
            • raven-worxR Offline
              raven-worxR Offline
              raven-worx
              Moderators
              wrote on last edited by
              #6

              then you just need to do this:
              @
              painter->drawPixmap( movie->currentPixmap() );
              @

              since you connect to QMovie's frameChanged() signal as i said and trigger an update, the cell will be redrawn every time the gif animation image changes.
              Thus you will see animated gifs in a listview.

              --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
              If you have a question please use the forum so others can benefit from the solution in the future

              1 Reply Last reply
              0
              • M Offline
                M Offline
                maxy
                wrote on last edited by
                #7

                Ok.Thanks for your help.I will implement this and let you know.

                Thanks

                1 Reply Last reply
                0

                • Login

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