Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set the header text of a QTreeView header

I have the same problem as:

What is the method to set the text for a QTreeWidget's header?

with one difference: I'm using a treeView, not tree widget, so the answer there didn't help.

I couldn't find in the documentation any instructions how to it.

So - how can I set the header text of a QTreeView?

like image 420
sara Avatar asked Sep 03 '12 09:09

sara


2 Answers

Ah... anyone getting frustrated with this with PyQt5 might like to try this:

self.ui.treeView.setHeaderHidden( False )
like image 57
mike rodent Avatar answered Nov 17 '22 08:11

mike rodent


It may be done in your model class that probably inherits QStandardItemModel.

Typically, you would call:

QStandardItemModel::setHorizontalHeaderLabels ( const QStringList & labels )

for text only, or

 QStandardItemModel::setHorizontalHeaderItem ( int column, QStandardItem * item )

if more customization is needed in the header items.

like image 19
Daniel Vérité Avatar answered Nov 17 '22 09:11

Daniel Vérité