Results 1 to 5 of 5

Thread: List View with sections for alphabetialy sorted list

  1. #1
    Join Date
    Mar 2010
    Posts
    36
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default List View with sections for alphabetialy sorted list

    Hi everybody,

    I need a special list view that shows the items in alphabetical groups. See the attached images.

    Indexed list on iPhone (middle picture)

    Similar for Android

    Any suggestions how I can achieve this?

    I was thinking about inserting a special item after each group in the model. But this would not be a very nice design. I suppose it's better to subclass QListView. But I'm not shure if it's a good aproach and how to do that.


    Cheers Luke
    Using Qt 4.7
    Developping on Win 7 and XP
    Using Qt Creator, Eclipse and Visual Studio
    Target Platforms Win, Linux and soon OS X

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: List View with sections for alphabetialy sorted list

    I would go for a custom model, which also provides the caption data (such as "A" or "T") with a custom data role to identify these data as a caption. Second use a custom delegate where you paint your items according to there type.

  3. #3
    Join Date
    Jul 2010
    Posts
    11
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: List View with sections for alphabetialy sorted list

    Try sub-classing QAbstractListModel and QAbstractProxyModel .

    I assume that your data is sorted.
    If your data is sorted (or stored in sorted container e.g. QMap) then it is sufficient to subclass QAbstractListModel.

    Override rowCount(), columnCount(), data(), setData(), and flags().
    When overriding data() function add implementation that return letter (A,B,C...) between original data.

    If data is not sorted then sort it first or subclass QAbstractProxyModel.

    In my opinion Model/View framework in Qt is one of most powerful features of Qt, once you master it, anything could be achieved.

    There is a good documentation and examples in Qt documentation on Model/View framework . See Model/View Programming, An Introduction to Model/View Programming and QAbstractItemModel class documentation.

  4. The following user says thank you to pervlad for this useful post:

    frz (12th October 2010)

  5. #4
    Join Date
    Mar 2010
    Posts
    36
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: List View with sections for alphabetialy sorted list

    Thanks guys!

    I'll try it with a custom model derived from QAbstractListModel.

    Cheers
    Using Qt 4.7
    Developping on Win 7 and XP
    Using Qt Creator, Eclipse and Visual Studio
    Target Platforms Win, Linux and soon OS X

  6. #5
    Join Date
    Jul 2010
    Posts
    1
    Thanks
    1
    Qt products
    Qt4

    Default Re: List View with sections for alphabetialy sorted list

    Hi there,

    I'm looking for the exact same kind of widget to display a music collection (artist > albums). I would really appreciate if you could provide some concrete code to get an example

    Thanks by the way, this is giving me a good way to start.

Similar Threads

  1. List View with renamable items?
    By MattT in forum Qt Programming
    Replies: 2
    Last Post: 17th July 2010, 11:21
  2. An old topic,custom list view
    By MorrisLiang in forum Qt Programming
    Replies: 2
    Last Post: 24th May 2010, 19:51
  3. Problem with list View
    By yuvaraj.yadav in forum Qt Programming
    Replies: 9
    Last Post: 29th April 2009, 15:02
  4. Custom widget in list view
    By fusoin23 in forum Qt Programming
    Replies: 1
    Last Post: 18th November 2006, 15:09
  5. KLed in a list view
    By villy in forum Qt Programming
    Replies: 6
    Last Post: 10th August 2006, 14:23

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.