2

I have created an application for my work which takes data from a database, does some calculations with it and dumps it into a table for viewing. Easy peasy. But, there has been a request to change the way information is shown. Previously it was using a simple tablewidget and a very standard table. My problem arises with the headers mostly. This is an idea of what I've been asked to change the layout to: enter image description here

As you can see, there is a top header with columnspan over the second header which in turn has it about the third. The third header (with little numbers) is not essential but the other two headers are. For what it's worth, under the months the calculated numbers will be displayed. My question is, how would I be able to create a table to make such a layout?

  • 2
    I think you may be out of luck, as Qt provides no APIs for spanning header items, or creating multiple header rows/columns. The usual suggestion here is to try the third-party [HierarchicalHeaderView](http://qt-apps.org/content/show.php/HierarchicalHeaderView?content=103154) widget. However, it is written in C++, and certainly not trivial to port to PyQt (even if it did what you wanted, which I'm not sure it does). There are other hacky possiblities (like [using a second table for the header](http://stackoverflow.com/a/8913740/984421)), but none of them seem completely satisfactory. – ekhumoro Mar 12 '14 at 20:52
  • Thanks for answering anyway, I did think it was possible., after all, that's more Excel's job. – Xtremesupremacy3 Mar 12 '14 at 23:35

1 Answers1

3

I read this 2 years ago and while there's no real answer I thought I'd share what I did for anyone still in need, my solution was to combine 3 QTableViews together to get the desired effect. You can see the code here, it's not pretty

https://github.com/adamerose/PandasGUI/blob/cded504a806cb41b37f77734b8c4f840829a9827/pandasgui/widgets/dataframe_viewer.py

enter image description here

pyjamas
  • 4,608
  • 5
  • 38
  • 70