Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

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.


  • Qt Champions 2019



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

    From http://doc.qt.io/qt-5/qlistwidget.html#details:

    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