Important: Please read the Qt Code of Conduct -

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):
            dirModel = QFileSystemModel()
            dirModel.setFilter(QDir.NoDotAndDotDot | QDir.AllDirs)
            tv = QTreeView()
            for column in range(1, dirModel.columnCount()):

    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., 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?

Log in to reply