1

I have a self created Qt-Model derieved by QAbstractTableModel. The data behind the model contains multiple QUuid-columns, whose cell-data I need to pass around the application. Due to design-reasons I don't want to show the QUuid-columns to the user, but keep them in the background to always guarantee access to the needed id-columns.

The data is bound to a Qtitan TableView Grid, where I can hide the column, but not totally remove it from the view. I can always reenable the visability which is not what I want.

So my question is if there are any options from the Qt-Model-side to hide a column or to avoid binding it to the view and just keep the data in the background.

Me3nTaL
  • 139
  • 2
  • 11
  • 1
    I think you have two choices: 1) Hide the columns in the view(s) 2) Don't expose the column data from the model (`columnCount()`, `data()` functions etc.), but, in the same time manage that data in the model. – vahancho Jul 18 '22 at 07:42
  • Probably a bit more 'brute force' than you want but using a `QSortFilterProxyModel` with suitably overridden [`filterAcceptsColumn`](https://doc.qt.io/qt-6/qsortfilterproxymodel.html#filterAcceptsColumn) member would (I think) achieve what you want. – G.M. Jul 18 '22 at 08:35

1 Answers1

1

You can subtract those columns from the visible columns by returning the column respectively in columnCount.

This would require to either move them to the end, or map the user visible column count to the underlying columns in your data() implementation.

It is probably a bit simpler to move those invisible columns to the end to avoid the mapping, but you can also do the mapping if you like.

int MyModel::columnCount(const QModelIndex& parent) const
{
  return allColumns - columnsToHide;
}
László Papp
  • 51,870
  • 39
  • 111
  • 135
  • But that results in empty cells. The column itself still exists though. – Me3nTaL Jul 19 '22 at 05:54
  • You need to modify the column count, and then maybe do not need the -1 here. – László Papp Jul 19 '22 at 06:14
  • Yes, I found a way, which is acceptable for me: the data behind my model consists of rows-, cells-, and column-classes. The columns I'd like to hide, I move to the end of the list where all columns are stored and then I subtract the count of the hidden columns of the columnsCount()-method. So the last columns which are hidden are cut off – Me3nTaL Jul 19 '22 at 06:45
  • @Me3nTaL: does the updated answer work for you? If not, anything else you need help with for this particular question? Thanks. – László Papp Jul 23 '22 at 11:47