14

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?

Lion King
  • 32,851
  • 25
  • 81
  • 143
  • Possible duplicate of http://stackoverflow.com/questions/19001933/qt-hide-column-in-qtableview and http://stackoverflow.com/questions/25726416/qt-display-not-all-fields-from-model – Ezee Oct 31 '14 at 13:30

1 Answers1

23

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

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

Andrea
  • 6,032
  • 2
  • 28
  • 55
  • 4
    How can the column value be found from the column name? It concerns me referencing by an int value when it's not something we have specified in the code to begin with. E.g., how does one know that future versions will default to that column having that int value? – SiliconBadger Jul 03 '19 at 06:50
  • How to hide column of QTreeWidgetItem ? – sonichy Aug 25 '20 at 02:42
  • I agree with SiliconBadger. There should be some `enum` or constant that represents the column ID. The documentation does not seem to have that for now. – Nav Feb 02 '22 at 06:59