View Full Version : How to set two rows in a table view Horizontal header?

9th April 2009, 17:16
We need to insert two rows in a table view header. But the QHeaderView looks like supporting only single row in a table header. How can we achieve to insert two rows in a table header.

Thanks in advance.

9th April 2009, 23:46
Please search the forum. As far as I remember the issue has already been brought up. From what I see even the "Similar threads" block on the bottom of this page suggests a thread with a solution.

10th April 2009, 11:14
Sorry iam not able to find the solution.
can you please view the attachment and suggest the procedure.

10th April 2009, 12:08
This thread might give you some ideas.


14th April 2009, 10:28
I have already tried the same, but iam not getting exactly what i need to show, when i used the verticallayout, its clearly differentiating the two headers, but in my case i want to have single horizontal headerview and in that one of the header should contain multiple headers.(please view the attachment). please guide me the approach.

14th April 2009, 23:14
I would subclass QHeaderView and reimplement most of it. But it's much work, unfortunately. QHeaderView is a very incomplete class that was probably meant to be finished in some undefined future that never came to be...

20th April 2009, 10:06
this (http://qt-apps.org/content/show.php/HierarchicalHeaderView?content=103154) :)

20th April 2009, 13:53
take a look at this :

QEXtendedGridView ( at qt-apps.org ) (http://www.qtcentre.org/forum/f-qt-software-16/t-qextendedgridview-20392.html)

21st April 2009, 16:39
We downloaded the HierarchicalHeaderviewhttp://qt-apps.org/content/show.php/HierarchicalHeaderView?content=103154 from QT-Apps. We are pleased to see the source code. Thank you for providing the details.

How can i add rows and columns to this table view. I got lost with the ExampleModel class.


23rd April 2009, 05:47
See Model\View programming in QT docs.

ExampleModel is for data in table. It contains _headerModel. _headerModel discribes header structure.
If you want add rows in table, implement rowCount in Example model (now it returns 0, i.e. no rows), and handle DisplayRole in data.

QVariant data(const QModelIndex& index, int role) const
QVariant v;
return v;
if(role==Qt::DisplayRole && index.isValid())
return QString("row %1 column %2").arg(index.row()).arg(index.column());
return QVariant();

25th April 2009, 17:09
Hi Barmaglodd,
I tried reimplementing the "insertRows" function. Called "beginInsertRows" and "endInsertRows()". But i get lost on what should we put between these two statements inside the function insertRows.

We are trying to insert rows in the example code provided by you before.

Request you to provide us a code snippet on how to insert rows into the table.

With Regards,

29th April 2009, 05:57
Sorry for late answer.
Where do you want to reimplement insertRows? If for table data, i realy recomend you read Model\View programming in Qt docs and Qt demos and examples. If you reimplement it for header model, it's a wrong way, header model is a tree not a table.