Congratulations to our 2022 Qt Champions!

QListView and QListWidget

  • I've been reading about those two classes ,But can't figure out exactly when to use them.

    for example , I wanted to create a list of labels to be displayed and when I click on the label something should happen.
    Instead of doing that I created a QListWidget with String , which works fine.
    But the question here is when should QListView be used and why?
    Thank you.

  • Lifetime Qt Champion

  • @MokJ
    QListWidget is derived from QListView. When you read the page, everything there which is added/overridden represents what the differences are between the base QListView and the "pre-designed" QListWidget implementation.


    QListWidget is a convenience class that provides a list view similar to the one supplied by QListView, but with a classic item-based interface for adding and removing items. QListWidget uses an internal model to manage each QListWidgetItem in the list.

    For a more flexible list view widget, use the QListView class with a standard model.

    That about sums up the differences. Adding/removing items interface. Plus it has its own model defined, instead of you using standard model or writing your own. That may or may not suit your particular data model.

  • Thanks @JonB and @jsulm .
    Can you explain with any sort of example verbally, No code just any clue, cause I have tried both QListView and QlistWidget so a bit more clarity would be appreciated.

Log in to reply