Results 1 to 7 of 7

Thread: Speed Up TreeView

  1. #1
    Join Date
    Jun 2007
    Posts
    52
    Thanks
    6

    Default Speed Up TreeView

    I have a QAbstractItemModel that interacts with a QTreeView. Currently it takes to long to load the tree and to scroll through the tree. Is there a way to speed up the tree?

    Description of the tree:
    1) Child nodes under root < 100
    2) Each child node might have as many as 40 branches
    3) The expand all function needs to be able to be applied
    4) Fast scrolling is required.

    We have tried several things to speed it up and haven't been able to get anywhere. My most recent attempt was to try to only have the view load what it can display in the viewport. I haven't been able to get that to work yet and I am on a deadline. Does anyone have any suggestions or obviously if you need more details let me know. Any help would be appreciated.

  2. #2
    Join Date
    Sep 2009
    Location
    UK
    Posts
    2,447
    Thanks
    6
    Thanked 348 Times in 333 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Speed Up TreeView

    Did you try the MVC (model, view, controller) approach? That way you only provide data as necessary.

  3. #3
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Speed Up TreeView

    How do you populate the tree?
    Can you show some source code?

    Avoid painting all the items. Only paint those that are on the screen.

  4. #4
    Join Date
    Jun 2007
    Posts
    52
    Thanks
    6

    Default Re: Speed Up TreeView

    I wish I could show you the code, but I legally can't. We are doing the model view approach, I don't know what the controller is though.

    Currently there are 2 things that are really slow, loading the tree when you initially start up and also doing an expand and collapse all. I am not sure if the paintevent will help with these.

  5. #5
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Speed Up TreeView

    I see you are using an abstract item model. This is the most important place to look for slowness.
    The view doesn't know anything about the data so the model tells the view what to do when more items are available.

    In plain English this means this:
    1. When you use an abstract item model and don't do some magic, it will be very slow when you add thousands of items because the model tells the view that it got thousands of new items to paint. The view, which is not very clever by its own, will happily paint all of them. A huge waste of resources as you see only a fraction of the items.
    2. When an item has even more child items, the tree view is a little bit smarter, it doesn't paint those child items. But, what happens if you do an expand all? All those child items get painted too resulting in a huge loss of resources.

    What you need to do in your model is tell the view to stop painting all the items.
    When you open a child item, the tree view calls canFetchMore(...) of the model. The model tells the view that it has more items to paint.

    You can reimplement the canFetchMore() and fetchMore() functions.

    Take a look at the QSqlQueryModel for example.

    ps: The controller, in Qt called the delegate, sits in between the model and the view. It tells the view how to draw certain items of the model and it tells the model how to update the data when something happens in the view (like an editor for example).

  6. #6
    Join Date
    Jun 2007
    Posts
    52
    Thanks
    6

    Default Re: Speed Up TreeView

    Alright, I will try that thanks

  7. #7
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Thanked 268 Times in 268 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Wiki edits
    20

    Default Re: Speed Up TreeView

    Ohh, and if you want to try something easier right away, and this will help:
    Do not add all your items at once to the model, add them incrementally using a timer for example.

Similar Threads

  1. speed up my imagemagick/qt editor
    By yoniekai in forum Qt Programming
    Replies: 5
    Last Post: 5th April 2011, 12:15
  2. how to speed up the replot?
    By rambo83 in forum Qwt
    Replies: 4
    Last Post: 16th December 2009, 11:51
  3. QTcpSocket speed problem
    By benelgiac in forum Qt Programming
    Replies: 4
    Last Post: 1st May 2007, 13:50
  4. Speed of static app
    By jcr in forum Qt Programming
    Replies: 1
    Last Post: 6th October 2006, 20:09
  5. speed of setdata - lots of items in treeview
    By Big Duck in forum Qt Programming
    Replies: 4
    Last Post: 6th July 2006, 12:53

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.