Best practice for a lot of tables: Create one model/view pair for each table OR use only one view and changing its model



  • I am storing a number of tables which are accessible through a comboBox by their name/ID.
    Only one table is being displayed at a time.
    The data of the table are stored in separate Qt model objects (QStandardItemModel for example).

    Now my question is: Which is the better approach

    a) create for each table a model/tableView pair and use a stackedWidget for switching between the tables when the user selects a table from the comboBox

    or

    b) create only 1 tableView and when the user selects a table from the comboBox use the setModel() function of the view to switch to the selected model/table

    ???


  • Moderators

    Hi, welcome to devnet.

    "better" depends on how complex your view class is. If it's just a standard QTableView without any customization then go for simplicity - use a single view. If, on the other hand, you' later want to customize the view, e.g. subclass the QTableView and add some customization for particular models, or use special delegates for some of the models then it might be easier to swap views then to adjust all the customizations on model change.
    There's no one answer here.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.