PDA

View Full Version : add model headers to treeview



Omid123
20th January 2015, 17:14
Hi there,

I made a model: model = new QStandardItemModel(2,1,this);
then, i set headers: model->setHeaderData(0, Qt::Vertical, QObject::tr("my Header"));

I set the model into tableview and treeview.
tableview works fine and shows me a table with headers, but, treeview only shows data and no headers.

can anyone help?

Omid

jefftee
20th January 2015, 17:32
The doc for QStandardItemModel::setHeaderData says that the signal QAbstractItemModel::headerDataChanged must be emitted manually, have you done that?

What is the return code from setHeaderData?

Are you trying to set the headers for the rows or the columns? Vertical headers are for the row and horizontal headers are for the columns. You may already know that, but thought I'd ask since horizontal headers are more common in my experience.

d_stranz
21st January 2015, 00:25
The doc for QStandardItemModel::setHeaderData says that the signal QAbstractItemModel::headerDataChanged must be emitted manually, have you done that?

He doesn't need to do this. If he is using QStandardItemModel (which it looks like he is), QStandardItemModel will emit the signal itself when the data changes. The only time you would need to emit this signal yourself is if you have derived a class from QAbstractItemModel and are modifying headers.

Tree views do not use vertical headers, only horizontal ones. Change Qt::Vertical to Qt::Horizontal and you'll see the head at the top of the tree.

jefftee
21st January 2015, 00:45
He doesn't need to do this. If he is using QStandardItemModel (which it looks like he is), QStandardItemModel will emit the signal itself when the data changes.
Thanks for correcting my post. At least I was on the right track regarding the vertical vs horizontal header. :)