1

This question is basically asking the same thing - Is it possible to use QAbstractTableModel with TableView from QtQuick.Controls?

I have a QAbstractTableModel with data in the rows and columns. I want to be able to specify which column in my model the view should be displaying. This is not at all obvious to do, any help would be appreciated.

Basic examples rely on unique role names to ensure the correct data arrives in a given column, eg:

TableView {
    TableViewColumn { role: "title"; title: "Title"; width: 100 }
    TableViewColumn { role: "author"; title: "Author"; width: 200 }
    model: libraryModel
}

The only hack I can think of is to assign each column in my model a unique role name, but this seems like a code smell, is there another simple way to specify the column index of my TableViewColumn?

mx5_craig
  • 108
  • 10
  • AFAIK, QML has abandoned the concept of columns. You might fake it with a ProxyModel, which maps from columns to roles? – derM - not here for BOT dreams Sep 13 '18 at 13:30
  • "The only hack I can think of is to assign each column in my model a unique role name", this is correct and Qt recommended way, I think. – m. c. Sep 13 '18 at 18:03
  • I was also surprised at the time that you can't directly use C++ model in QML. For some reason Qt/C++ concept of roles is slightly different. For myself, I realized that Qt concept of "columns" it's the same as QML "roles". – folibis Sep 13 '18 at 18:18
  • Thanks for the help on this, I am surprised by this but having spent some time trying to figure out what I was missing I am relieved to know I'm not going totally mad! – mx5_craig Sep 14 '18 at 12:40

0 Answers0