Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Views - what are the correct rules to use models?
QtWS25 Last Chance

Views - what are the correct rules to use models?

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
viewmodeldelegatechoosedesign
2 Posts 2 Posters 561 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • jeanmilostJ Offline
    jeanmilostJ Offline
    jeanmilost
    wrote on last edited by
    #1

    I my projects I often need to create views, which are linked to models written in c++. From my perspective, and the way I understood how view/model/delegate systems work, I prefer select the basic model which seems the best designed to interact with the view as a parent for my custom model, e.g a ListView needs a QAbstractListModel, whereas a TableView needs a QAbstractTableModel, because always according to my point of view, such models contain the functions required by the view to manage the format they own, e.g a TableView understands what a column is, whereas a ListView know nothing about columns, for that reason a QAbstractTableModel is a better choice as a base to write my custom model when I have to deal with a TableView.

    However my supervisor does not agree with me. From his point of view, a model should always match with the data it handles. For example, we recently needed to modify a ListView to support a small concept of columns. These columns are written in custom qml components and delegates, and the ListView itself continue to know nothing about columns. For that reason I proposed to use a QAbstractListModel, but my supervisor think I'm wrong and a QAbstractTableModel should be used instead, because the model should include the concept of columns.

    I admit to being a little puzzled about that. For that reason, I want to know:

    • Is it better to select a model based on its interaction with the view, or on the data it handles?
    • May any type of model be used with any view, e.g may a QAbstractTableModel be used with a ListView without problems, or is it a mistake (and why)?
    • What are the correct rules and good habits to apply to select a model for a view?
    • What should (or should never) be done when selecting a model for a view, and why?
    J.HilkJ 1 Reply Last reply
    0
    • jeanmilostJ jeanmilost

      I my projects I often need to create views, which are linked to models written in c++. From my perspective, and the way I understood how view/model/delegate systems work, I prefer select the basic model which seems the best designed to interact with the view as a parent for my custom model, e.g a ListView needs a QAbstractListModel, whereas a TableView needs a QAbstractTableModel, because always according to my point of view, such models contain the functions required by the view to manage the format they own, e.g a TableView understands what a column is, whereas a ListView know nothing about columns, for that reason a QAbstractTableModel is a better choice as a base to write my custom model when I have to deal with a TableView.

      However my supervisor does not agree with me. From his point of view, a model should always match with the data it handles. For example, we recently needed to modify a ListView to support a small concept of columns. These columns are written in custom qml components and delegates, and the ListView itself continue to know nothing about columns. For that reason I proposed to use a QAbstractListModel, but my supervisor think I'm wrong and a QAbstractTableModel should be used instead, because the model should include the concept of columns.

      I admit to being a little puzzled about that. For that reason, I want to know:

      • Is it better to select a model based on its interaction with the view, or on the data it handles?
      • May any type of model be used with any view, e.g may a QAbstractTableModel be used with a ListView without problems, or is it a mistake (and why)?
      • What are the correct rules and good habits to apply to select a model for a view?
      • What should (or should never) be done when selecting a model for a view, and why?
      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by J.Hilk
      #2

      @jeanmilost
      I can't answer all your questions, as I'm not an expert on Qt's Model/View system, what I do know is,

      that all models have a QAbstractItemModel as base model and that is also the ABI for all views.
      For that reason alone, you can assign all models to all views. You will however not get a useful representation of all your data in all views.

      As I understand it, and anyone fell me to correct me here, the other higher level classes of models are only there to make your life easier, as in you do not have to implement all functions/functionalities of the whole AbstractItemModel class


      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      1

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved