Important: Please read the Qt Code of Conduct -

QTreeView hideColumn() has no function

  • Hello, I work on a little pyside2 application with a QTreeView which comes from an ui file.

                print(self.treeView.isColumnHidden(1)) # False
                print(self.treeView.isColumnHidden(2)) # True

    but column no. 2 is still visible. Are there any requirements for hideColumn() to work properly? Same effect with setColumnHidden(x, True).

    Don't know if it's important: I use a selectionModel and "SingleSelection" mode with "SelectRows" selection behavior. That all works.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    Might be a silly question but how many columns does your model have ?

    Can you provide a minimal example showing that behaviour you have ?

    By the way what bindings are you using ? PySide2 ? PyQt5 ? which version ?

  • @SGaist thank you very much. The model has 4 columns which are all displayed in the treeview. I will provide an example this evening.

  • I've tried it with a simplified version with my Item and ItemModel class (derrived from QAbstractItemModel) and... it works, so I don't post an example here. Have to examine the differences now...

  • I've found the solution. After initializing everything I called header().restoreState() to restore column withs and everything, and this resetted my hideColumn settings.

  • Banned

    Oh dang sorry I actually ran into this as well -- yes every time you update your model content (I believe) you have to reinstate the hidden columns and I think perhaps a few other things -- I will see if I can find this as I stumbled across this within the documentation somewhere

Log in to reply