Possibly by subclassing a QAbstractListModel? AFAIK there is no way to set headers for a QListView, is there?
Possibly by subclassing a QAbstractListModel? AFAIK there is no way to set headers for a QListView, is there?
Why would you want to add a header if there is only one column in the view?
As the docs say:This view does not display horizontal or vertical headers; to display a list of items with a horizontal header, use QTreeView instead.
Well, for asthetic purposes mainly. But I didn't say that there would be only one column in the viewThere will be a between two and four, depending on the tab being viewed.
But anyway, it seems to be possible for a QAbstractListView, since it inherits from the QAbstractItemModel - and that has a headerData() method.
I ask this because in my program, updating a QSimpleItemModel using the setData() method takes about 20 seconds when the newsserver being listed has 176.000 groupsWhich freezes the GUI for about 20 seconds - which may be acceptable to whoever wrote Grabit, but it's exactly what I'm trying to avoid in my program. So I thought that by creating a simple read-only model, and by setting the model of the QListView to the newly created model, I could speed things up quite a bit. This is true, right? Calling setData() seems to have a lot of overhead with large amounts of rows, as searching this forum would have me believe ...
/edit : just implemented it - it works like jacek says with a QTreeView and a QAbstractItemModel. Bugger, I was trying to get away from those lines drawn down the side, since it looks ugly when they aren't really related to each other. But it still holds true for the speed issue.
ThanksThat gets rid of teh ugly at least
Do you know if it will be fast to reassign a model subclassed from a QAbstractItemModel?
But QListView can display only a single column... You should use QTreeView if you want more.
QAbstractListView supports a single column data only as well.But anyway, it seems to be possible for a QAbstractListView, since it inherits from the QAbstractItemModel - and that has a headerData() method.
If you have speed problems, don't use setData to update the model but create a custom method which will insert all items at once. Otherwise all your views will update each time you use setData() or insertRows().
Woah. I just subclassed a QAbstractItemView and now I just destroy the old model and set the new model with all the data added in by the constructor of the model. It's damned near instant : it took about 6 seconds to add them to a QStandardItemModel, compared to less than a second!
Only drawback is now that I have to sort my QStringList and then parse it in a for-loop now to sort the newsgroups, which slows things down again a lot, but it still only takes about 15 seconds to parse and display 176.000+ this way, and the GUI stays more or less responsive nowI added in a model QProgressDialog though to show progress. I normally avoid modals like the plague, but in this case it's warranted I think
Thanks for all the tips guys. This forum is a really big help.
Bookmarks