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. Adding items to ListWidget is slow
Forum Updated to NodeBB v4.3 + New Features

Adding items to ListWidget is slow

Scheduled Pinned Locked Moved General and Desktop
4 Posts 3 Posters 4.1k 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.
  • A Offline
    A Offline
    alexandros
    wrote on last edited by
    #1

    Ok, not so slow for a normal application, but I am developing an appllication, that, depending on user actions, a listwidget is being filled. The thing is that the entries are far too many and may be up to 200-300 per sec.
    It works more than OK if, when I add the items I use the following code:
    @ui->listWidget->additem("MyNewItem text here");@

    BUT I want the items to be editable with double click etc, so I have to fix the flags to each of them as far as I know. So, the above one-liner becomes this:
    @QListWidgetitem *item = new QListWidgetItem;
    item->setText("MyNewItem text here");
    item->setFlags(item->flags() | Qt::ItemIsEditable);
    ui->listWidget->addItem(item);@

    This adds one or two milliseconds more to the addition of each of my items, and, considering how many items I'm adding per second, the program slows down a lot.

    Is there any way to solve this problem? Is there any way to tell the listwidget, if it has editTriggers, then all the items added to it to be editable by default so as not to have to do it for each individual item?

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mlong
      wrote on last edited by
      #2

      Have you considered using a QListView instead of a QListWidget in order to decouple the model from the view?

      Software Engineer
      My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        alexandros
        wrote on last edited by
        #3

        [quote author="mlong" date="1347293588"]Have you considered using a QListView instead of a QListWidget in order to decouple the model from the view?[/quote]

        Thanks for this! Will just the conversion from QListWidget to QListView make the whole thing run faster? What will I gain?

        1 Reply Last reply
        0
        • A Offline
          A Offline
          andre
          wrote on last edited by
          #4

          For one, you gain the option to insert multiple rows in a single call. Also, you don't have to create actual objects for each of your cells, which eliminates the repeated heap memory allocation. Memory allocations are quite slow, so that might help.

          However, based on this alone, there is no definitive way to say if you are going to gain speed. At least, you will gain more vectors for optimization. To find out what speed increases you get, there is just one answer: benchmark. The same goes for your current solution by the way. You should analyze what exactly takes the most time in your current situation, and focus your efforts on that. Personally, I doubt that the flag setting is the issue. I expect the constant re-layouting and repainting of the list to be at least an order of magnitude more expensive.

          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