How to hide some columns in a QTreeView?

Lion King picture Lion King · Oct 31, 2014 · Viewed 8.3k times · Source

I have a QTreeView model, that model has four columns as the following (Name, Size, Type, Data Modified).

I want is to remove the (Size, Type, Data Modified) columns, and leave only the column named Name.

QFileSystemModel *sysModel = new QFileSystemModel;
sysModel->setRootPath("");
sysModel->setFilter(QDir::Dirs | QDir::NoDotAndDotDot);
ui->treeView->setModel(sysModel);

I want to know, What function is responsible for that?

Answer

Andrea picture Andrea · Oct 31, 2014

QTreeView::setColumnHidden(int column, bool hide) does the trick.

You can also use QTreeView::hideColumn(int column).