Can I have more than one row in the table header in Qt?

I use Qt4, and I have a QTableView that displays data using a custom model. I would like to have two rows in the table header, ideally, with some cells in the first row spanning several columns. Is it possible?

+6
qt qt4
source share
4 answers

I was also looking for a solution to this problem. I found this class: HierarchicalHeaderView on qt-apps.org by Barmaglodd (Krasnoshchekov Petr).

This decision goes beyond what you (and I) need. In addition, I cannot use their solution because of their copyright notice.

This post from blog.qt.digia.com by Andy Shaw shows you how to overlay QComboBoxes on the title. In my decision, I did the same with a different header. This is similar to how they imposed a QTableView on a QTableView for an example Qt Frozen column . For this solution, you need to subclass QTableWidget and QHeaderView. Also, if you want the user to customize the column width, which requires additional work.

Tip. Overload SizeHint to get a 2x height of the normal height of the main heading, align the main heading text down and draw another headerview on top of the usual one, do it further

 showEvent(QShowEvent* e) 

method.

+2
source share

I had a similar problem regarding multiple QTableView header lines. I solved this with a simple "\ n" in the text of the column header.

+3
source share

You can create your own title by creating a QTableWidgetItem and then using setHorizontalHeaderItem() . The method takes a column number, so I'm not sure if this will cover multiple columns initially - however, at least you can use the same QTableWidgetItem for multiple columns.

Regarding the use of two lines in the header, I do not think that this is currently supported. However, you could add this functionality by copying your own derived QTableWidget class if you are ambitious.

+2
source share

Impressed by the HierarchicalHeaderView, I created a Python port and a simple model for displaying pandas DataFrames with multi-level headers (MultiIndex) in a QTableView.

Here are the first dataframemodel results. upd: it is rather slow with large DataFrames

+1
source share

All Articles