Results 1 to 9 of 9

Thread: Is it possible to add headers to a QListView?

  1. #1
    Join Date
    Aug 2006
    Posts
    163
    Thanks
    12
    Thanked 5 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Is it possible to add headers to a QListView?

    Possibly by subclassing a QAbstractListModel? AFAIK there is no way to set headers for a QListView, is there?

  2. #2
    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: Is it possible to add headers to a QListView?

    Why would you want to add a header if there is only one column in the view?

  3. #3
    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: Is it possible to add headers to a QListView?

    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.

  4. #4
    Join Date
    Aug 2006
    Posts
    163
    Thanks
    12
    Thanked 5 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Is it possible to add headers to a QListView?

    Quote Originally Posted by wysota View Post
    Why would you want to add a header if there is only one column in the view?
    Well, for asthetic purposes mainly. But I didn't say that there would be only one column in the view There 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 groups Which 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.

  5. #5
    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: Is it possible to add headers to a QListView?

    Quote Originally Posted by Valheru View Post
    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.
    Try changing rootIsDecorated property to false or use QTableView.

  6. #6
    Join Date
    Aug 2006
    Posts
    163
    Thanks
    12
    Thanked 5 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Is it possible to add headers to a QListView?

    Thanks That gets rid of teh ugly at least Do you know if it will be fast to reassign a model subclassed from a QAbstractItemModel?

  7. #7
    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: Is it possible to add headers to a QListView?

    Quote Originally Posted by Valheru View Post
    Do you know if it will be fast to reassign a model subclassed from a QAbstractItemModel?
    No, I don't. I've never tried to do such benchmarks.

  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: Is it possible to add headers to a QListView?

    Quote Originally Posted by Valheru View Post
    Well, for asthetic purposes mainly. But I didn't say that there would be only one column in the view There will be a between two and four, depending on the tab being viewed.
    But QListView can display only a single column... You should use QTreeView if you want more.

    But anyway, it seems to be possible for a QAbstractListView, since it inherits from the QAbstractItemModel - and that has a headerData() method.
    QAbstractListView supports a single column data only as well.

    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().

  9. #9
    Join Date
    Aug 2006
    Posts
    163
    Thanks
    12
    Thanked 5 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Is it possible to add headers to a QListView?

    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 now I 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.

Similar Threads

  1. Replies: 4
    Last Post: 27th September 2006, 13:34
  2. How can I disable the QListView Sorting?
    By darpan in forum Qt Programming
    Replies: 3
    Last Post: 27th June 2006, 10:36
  3. QTableView : headers disappear
    By xavier in forum Qt Programming
    Replies: 2
    Last Post: 8th May 2006, 16:57
  4. Key Events for QListView
    By bmesing in forum Qt Programming
    Replies: 2
    Last Post: 4th April 2006, 09:29
  5. Keeping focus at bottom of QListView
    By jakamph in forum Qt Programming
    Replies: 4
    Last Post: 10th January 2006, 14:45

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.