I'm using Qt4 and I have a QTableView
which displays data using a custom model. I'd like to have two rows in the table header, ideally with some of the cells in the first row spanning multiple columns. Is this possible?
I too was looking for a solution to this problem. I've found this class: HierarchicalHeaderView at qt-apps.org by user Barmaglodd (Krasnoshchekov Petr).
That solution goes over and beyond what you (and I) need. Also, I cannot use their solution due to their copyright notice.
This post from blog.qt.digia.com by Andy Shaw shows you how to overlay QComboBoxes over a header. In my solution, I've done the same thing with another header view. This is similar to how they overlaid a QTableView on a QTableView for the Qt Frozen column example. For this solution, you do need to subclass both the QTableWidget and QHeaderView. Also, if you want to let the user adjust column width that takes extra work.
Tip: overload the SizeHint to give a height 2x of the normal height of the 'main' headerview, align the text of the main header view to the bottom and draw the other headerview on top of the normal one, do this in the
showEvent(QShowEvent* e)
method.