Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Cannot hide columns except name in QTreeview
Forum Update on Monday, May 27th 2025

Cannot hide columns except name in QTreeview

Scheduled Pinned Locked Moved Unsolved Qt for Python
2 Posts 1 Posters 712 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    dancaer69
    wrote on last edited by dancaer69
    #1

    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.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dancaer69
      wrote on last edited by dancaer69
      #2

      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?

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved