Can I have more than one line in a table header in Qt?

后端 未结 4 2002
隐瞒了意图╮
隐瞒了意图╮ 2020-12-19 06:40

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 cell

相关标签:
4条回答
  • 2020-12-19 06:43

    I've had a similar problem regarding the multiple headder lines of a QTableView. I solved it using a simple "\n" in the column header text.

    0 讨论(0)
  • 2020-12-19 06:44

    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.

    0 讨论(0)
  • 2020-12-19 06:52

    You can make a custom header by making a QTableWidgetItem and then using the setHorizontalHeaderItem(). The method takes a column number, so I am not sure if that will allow for spanning multiple columns natively -- however, at the very least you could use the same QTableWidgetItem for several columns.

    As far as using two rows in the header, I do not believe this is currently supported. However, you could probably add this functionality by rolling your own derived class of QTableWidget if you are ambitious.

    0 讨论(0)
  • 2020-12-19 07:02

    Under the impression of HierarchicalHeaderView I've made a Python port of it and a simple model to display pandas DataFrames with multilevel headers (MultiIndex) in QTableView.

    Here're the first results dataframemodel. upd: it's quite slow with big DataFrames

    0 讨论(0)
提交回复
热议问题