How to get set model correctly



  • Hello people!

    I have a QAbstractTableModel class, a delegate class, QListView and QTable view.
    in the model class (which inherits the QAbstractTableModel) I have a Qlist of data object.
    in the delegate class I paint it for the view, so in the view part I do the following
    listView->setmodel(model);
    tableView->setModel(model);

    listView->setItemDelegate(delegate);
    tableView->setItemDelegate(delegate);

    and the output for the list View is exactly what I want, rows painted by the delegates, but for the table view I have the same number of row as in the list and the columns also but all items in a row has the same value, I don't guess why
    can you answer me please?



  • Sounds like a problem in the data() implementation of your model.



  • I think the problem is the columnCount() and rowCount()
    my rowCount returns dataList.size(); and it's ok for list view but for table view it is extra rows and how can I fix it?



  • Eh? You only want to show a subset of the data that is visible in the table view in the list view? That is: the list should have fewer rows than the table?

    If so, you cannot use the (exact) same model. You might be able to use a proxy model to filer your base model back to the rows you want to show in the list though.



  • So I cannot use tableModel for both list and table view?



  • Of course you can!

    You just can't expect the same model to have a different number of rows for two different views.



  • Aaah, ok thank you


Log in to reply
 

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