resizeColumnToContents() not working Qt C++
c++, qt, treeview
Solution
I worked on a project that involves `QTableWidget` and I've used the header of the tablewidget to set the resize mode, looking the documentation of QTreeView I can see that have a header too, then this code should works for you:
EDIT:
If you are using Qt4:
ui->treeView->header()->setResizeMode(0, QHeaderView::ResizeToContents);
ui->treeView->header()->setResizeMode(3, QHeaderView::ResizeToContents);
Then if you are using Qt5:
ui->treeView->header()->setSectionResizeMode(0, QHeaderView::ResizeToContents);
ui->treeView->header()->setSectionResizeMode(3, QHeaderView::ResizeToContents);
Problem
I have this treeView widget with the following building function: ``` void berichtenhistorie::DirectoryDisplay() { QFileSystemModel *dirModel = new QFileSystemModel(this); dirModel->setRootPath("path"); dirModel->setFilter(QDir::Files | QDir::NoDotAndDotDot | QDir::AllDirs); ui->treeView->setModel(dirModel); ui->treeView->setRootIndex(dirModel->index("path")); ui->treeView->hideColumn(1); ui->treeView->hideColumn(2); ui->treeView->setSortingEnabled(true); ui->treeView->sortByColumn(3); ui->treeView->resizeColumnToContents(0); ui->treeView->resizeColumnToContents(3); } ``` But the `ui->treeView->resizeColumntoContents(#);` I don't get any error's, but it won't resize it. It looks like this: But this is how it supposed to look like How do I make this working properly? Thanks!