Results 1 to 17 of 17

Thread: Too slow adding & defining items to QTreeWidget

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Too slow adding & defining items to QTreeWidget

    Quote Originally Posted by Billy Lee Black View Post
    Is there any other kind of widget I can use instead of QTreeWidget to do this? I have to manage lots of items in the view.
    You could try QTableView and a custom model. This way you can optimise item insertion to the maximum, but without any numbers it's hard to say whether it will be fast enough for you (some people reported 10x speed increase with custom model).

  2. #2
    Join Date
    Jun 2007
    Posts
    12
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Too slow adding & defining items to QTreeWidget

    Quote Originally Posted by jacek View Post
    You could try QTableView and a custom model. This way you can optimise item insertion to the maximum, but without any numbers it's hard to say whether it will be fast enough for you (some people reported 10x speed increase with custom model).
    About the numbers, I am talking about 10.000 more items in the item view. It is just like the program Wireshark (Ethereal). So, I will need it very fast, because I am receiveing packages every time to show to the users.

    But thanks for the tip. I will try the QTableView

  3. #3
    Join Date
    Jun 2007
    Posts
    12
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Too slow adding & defining items to QTreeWidget

    Well, I´ve made a custom Model and tried it with QTreeView and QTableView.

    But both are still too slow even though my model is really simple.

    In my application, I have like 8 columns in the view. I have to sniff network packets and print them in the view when I receive them. So, I am adding items to the view a lot of times, and each time I have to fill all the columns for each item added.

    I really don't know anymore what to do. Will I have to implement a custom view too?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Too slow adding & defining items to QTreeWidget

    How do you add items to the model? One cell at a time or whole rows/subtrees?

  5. #5
    Join Date
    Jun 2007
    Posts
    12
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Too slow adding & defining items to QTreeWidget

    Well, I made a class that stores the data for all the columns of a row.

    I set all the texts for the entire row and after that I add the row to the model.

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

    Default Re: Too slow adding & defining items to QTreeWidget

    Can we see the code?

  7. #7
    Join Date
    Jun 2007
    Posts
    12
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Too slow adding & defining items to QTreeWidget

    This is my method for adding one item( a row ) to the tableview:

    Qt Code:
    1. void AkViewItemModel::addItem(AkViewWidgetItem *newItem)
    2. {
    3. if(!newItem)
    4. return;
    5. int position = mItemsList.count();
    6. beginInsertRows(QModelIndex(), position, position);
    7. newItem->mViewWidget = mHeaderItem->akViewWidget();
    8. mItemsList.append(newItem);
    9. endInsertRows();
    10. }
    To copy to clipboard, switch view to plain text mode 

    And below is the method to add a list of items:

    Qt Code:
    1. void AkViewItemModel::addItems(QList<AkViewWidgetItem *> items)
    2. {
    3. int beginRow = mItemsList.count();
    4. int numItems = items.count();
    5. beginInsertRows(QModelIndex(), beginRow, beginRow+numItems-1);
    6.  
    7. AkViewWidgetItem *item = NULL;
    8. for(int i = 0; i < numItems; i++)
    9. {
    10. item = items[i];
    11. item->mViewWidget = mHeaderItem->akViewWidget();
    12. mItemsList.append(item);
    13. }
    14. endInsertRows();
    15. }
    To copy to clipboard, switch view to plain text mode 

    When I add a lot of single items, it is really slow! But if I accumulate some items in my application and then add them through a list, it becomes a lot faster and solves my problem.

    Why are these methods beginInsertRows and endInsertRows so slow?

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

    Default Re: Too slow adding & defining items to QTreeWidget

    These methods are not slow. But they cause some signals to be emitted and each emition triggers a redraw of all the views displaying the model. So if you add 100 items a second then your application is busy refreshing the views. That's why it's better to accumulate changes and update the model in chunks.

Similar Threads

  1. Removing items properly from qtreewidget item
    By Djony in forum Qt Programming
    Replies: 6
    Last Post: 21st November 2006, 12:20

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
  •  
Qt is a trademark of The Qt Company.