Results 1 to 11 of 11

Thread: QListView unresponsive when painting images

  1. #1

    Exclamation QListView unresponsive when painting images

    Hello
    I have set up a QAbstractListModel together with a QStyledItemDelegate and QListView.
    In the model i have a method called "populate" which will search the local disk for some data, and then append it to the data list in the model via a signal. The signal invokes layoutChanged() (don't know how to use dataChanged anywhere except in the obligatory data method), which will then refresh the layout with the new data. (This happens only once)
    The QStyledItemDelegate draws the items on the QListView in iconMode gridview.
    Everything is working except the QListView being unresponsive, lagging, flicks and won't allow me to scroll for a long time.
    The messages i get in the console are:
    QBuffer::seek: Invalid pos: -345244657
    QBuffer::seek: Invalid pos: -345244657

    - multiple times everytime i move my mouse in the QListView.
    I did some research before writing this, but couldn't find anything useful.
    I suspect this being the main reason on why the QListView is so unresponsive, and i think it's something related to the QIcon i make.
    However i did some profiling and saw that the paint method in the Delegate got called over 200 times in an elapsed time of 1 minute without me touching the mouse.

    My code:
    http://pastebin.com/gjKJwJuU

    Things to note:
    I use PyQt5 but can understand slight C++ code.
    Pseudo code will only be useful for me if you include the methods being called.

    Edit #1:
    I just realized that with the fetchMore method, I don't need to emit layoutChanged so i removed that.
    I also moved the endResetModel() call up to the append method, because that's when items are actually added into the model.
    This changed nothing. ListView is still being unresposive/lagging. I also tried only adding 3-5 items to the list still getting same results...

    Edit #2:
    Okay so i stopped the paint method in the delegate from painting the images, which seems to have fixed the laggy QListView...
    I also stopped getting the QBuffer::seek invalid pos: -xxxxxx messages.
    So now i have another question.
    How do i fix the lagging in the QListView when painting images?

    I'm changing the title to this question instead of: QBuffer::seek invalid pos: -xxxxxx.
    Last edited by isplasher; 4th May 2015 at 17:55.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,356
    Thanks
    3
    Thanked 5,010 Times in 4,789 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Blog Entries
    4
    Wiki edits
    10

    Default Re: QListView unresponsive when painting images

    In my opinion your thread does totally nothing.

    The following code:

    Python Code:
    1. data_thread.started.connect(fetch_instance.local)
    To copy to clipboard, switch view to plain text mode 

    will cause fetch_instance.local to be called in the main thread and not the worker thread. Whatever you do in this function will make the UI unresponsive.
    Last edited by wysota; 4th May 2015 at 19:21.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,359
    Thanks
    36
    Thanked 1,533 Times in 1,484 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QListView unresponsive when painting images

    Quote Originally Posted by isplasher View Post
    The signal invokes layoutChanged() (don't know how to use dataChanged anywhere except in the obligatory data method), which will then refresh the layout with the new data.
    If you add data, why not use beginInsertRows() endInsertRows()?

    Cheers,
    _

  4. #4

    Default Re: QListView unresponsive when painting images

    Quote Originally Posted by wysota View Post
    In my opinion your thread does totally nothing.

    The following code:

    Python Code:
    1. data_thread.started.connect(fetch_instance.local)
    To copy to clipboard, switch view to plain text mode 

    will cause fetch_instance.local to be called in the main thread and not the worker thread. Whatever you do in this function will make the UI unresponsive.
    Hello, thank you for answering.
    The thread is working. You can see that i move the fetch_instance to the thread just above that code. I can also confirm this, because when i start the process, i can still move the GUI around, and everything is okay.

    Quote Originally Posted by anda_skoa View Post
    If you add data, why not use beginInsertRows() endInsertRows()?

    Cheers,
    _
    I actually just tried this, and the issue still remains.
    I tried adding the two calls in the append method in my code.

  5. #5

    Default Re: QListView unresponsive when painting images

    I just made a new discovery!
    While surfing on the net I stumbled upon QPixmapCache. While thinking it was the solution to my issue, i set it up.
    Unfortunately the issue still remains, but i discovered a symptom.
    To be sure i setup the caching correctly i made it print "from cache", "new image" depending on if the image was fetched from the cache, or was created anew.
    This showed some interesting results. On start it printed "new image" about 15 times as expected. I Expected 15 times because i set the limit in the fetchMore
    method to 15.
    Then i try moving the mouse inside the ListView, without scrolling, just moving the mouse around abit. This made the console go wild with alot of mixed messages of
    "from cache" and "new image", which about 60-70% of the messages were "new image". With this i think i finally narrowed down the cause of why the gui is lagging.
    It suggests that somehow the view is not only painting the needed (visible) images, but everything when you move your mouse inside the view.
    This however hasn't solved my problem, so please don't think that i still don't need help. I just wanted to give an update on what i have found.
    Last edited by isplasher; 5th May 2015 at 17:39.

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,356
    Thanks
    3
    Thanked 5,010 Times in 4,789 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Blog Entries
    4
    Wiki edits
    10

    Default Re: QListView unresponsive when painting images

    What happens if you increase the size of the pixmap cache?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7

    Default Re: QListView unresponsive when painting images

    Quote Originally Posted by wysota View Post
    What happens if you increase the size of the pixmap cache?
    Wow, so i just multipled the cache with 1000 (10240*1000) and it helped alot.
    The gui was still lagging but not as much as before.

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,356
    Thanks
    3
    Thanked 5,010 Times in 4,789 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Blog Entries
    4
    Wiki edits
    10

    Default Re: QListView unresponsive when painting images

    Quote Originally Posted by isplasher View Post
    Wow, so i just multipled the cache with 1000 (10240*1000) and it helped alot.
    The gui was still lagging but not as much as before.
    The effect you observed before was caused by cache flickering. How large are your images? Isn't the lagging caused by scaling pixmaps?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9

    Default Re: QListView unresponsive when painting images

    Quote Originally Posted by wysota View Post
    The effect you observed before was caused by cache flickering. How large are your images? Isn't the lagging caused by scaling pixmaps?
    Oh i see.. I completely forgot about the image size.
    The images i use mostly have the dimensions 1500x2100px. They are about 2mb each.
    After reading that i now realize why all this was happening.. (facepalms)
    Anyway, yes, i think you're right about the pixmap scaling. Do you have any solutions, other than using smaller images?

  10. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,356
    Thanks
    3
    Thanked 5,010 Times in 4,789 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Blog Entries
    4
    Wiki edits
    10

    Default Re: QListView unresponsive when painting images

    Scale them once before adding them to your model and use the thumbnail instead of the original image.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. The following user says thank you to wysota for this useful post:

    isplasher (5th May 2015)

  12. #11

    Default Re: QListView unresponsive when painting images [Solved]

    Right.
    Was thinking of the same approach.
    Thank you for your help, kind sir.

Similar Threads

  1. Replies: 8
    Last Post: 17th May 2012, 11:09
  2. QSharedMemory, signals and QBuffer
    By sky in forum Qt Programming
    Replies: 1
    Last Post: 23rd November 2011, 05:06
  3. QBuffer::readLine()
    By vfernandez in forum Qt Programming
    Replies: 2
    Last Post: 23rd April 2010, 20:57
  4. how can convert QFile to QBuffer?
    By learning_qt in forum Qt Programming
    Replies: 3
    Last Post: 16th November 2009, 13:34
  5. QBuffer bytesWritten() problem
    By QAlex in forum Qt Programming
    Replies: 3
    Last Post: 29th September 2009, 09:05

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.