Important: Please read the Qt Code of Conduct -

QListView with Groups

  • I'd like to create a ListView with groups, ala .NET's ListView class. The end goal is something similar to Ubuntu's System Settings dialog, with a root item represented by header text, and the subset of items displayed by clickable icons.

    I'm a bit confused by my options. QListView may not be appropriate, as it is designed to handle non-hierarchical lists. QTreeView, however, isn't quite right either, because I want the subitems to be displayed in an icon view.

    Will this require just a custom QItemDelegate, or will I need to implement a new subclass of QAbstractItemView?

  • Moderators

    implementing a custom QAbstractItemView is overkill in almost all situations :)

    A custom QItemDelegate may work, i am not sure if it will work with a QListView with setViewMode(QListView::IconMode).

    I would suggest you compose a custom widget. With QLabels for the headlines and a QListView with icon-mode set for the sub-items.
    You can then use stylesheets to hide the frame of the listview etc.
    To have a single selection across all the list views will be a bit tricky but possible.

  • I think I take your meaning. As I geared up to subclass QAbstractItemView, it also became evident how niche my new class would be. Based on this, I decided to take your advice of composing a custom widget.

    If anyone should want to subclass QAbstractItemView, this is a good article to get you started.