Unsolved Cannot hide columns except name in QTreeview
-
I'm trying to display filesystem directories in a combobox with a treeview and I cannot hide any column except name.
I tried anything relative I found but nothing works. Here is the related code with the latest attempt before create this thread, which also doesn't work:class SavefileDialog(QDialog, Ui_savefileDialog): def __init__(self,parent=None): QDialog.__init__(self,parent) self.parent=parent self.setupUi(self) dirModel = QFileSystemModel() dirModel.setFilter(QDir.NoDotAndDotDot | QDir.AllDirs) dirModel.setRootPath(QDir.homePath()) dirModel.removeColumn(1) tv = QTreeView() self.cbSave.setView(tv) #tv.header().hide() for column in range(1, dirModel.columnCount()): tv.hideColumn(column) self.cbSave.setModel(dirModel)
With above no column is hidden. If I change 1 to 0, then the name column is hidded and all others are still visible.
Am I doing something wrong, or is a Qt bug?
I am on arch linux with Qt 5.15 version. -
I solved this by using treeview' s setColumnHidden instead.
self.tv.setColumnHidden(column, True)
But I found another problem with treeview in combobox. The combobox collapses when I click anywhere inside. Is there any way to prevent collapse when I click on the little arrow to expand a directory?