
Source (link to git-repo or to original if based on someone elses unmodified work): Add the source-code for this project on opencode.net
Hierarchical header view for QTableView.
Header data is described by QAbstractItemModel. Text in cells of header can be rotated.
10 years ago
Version 1.3.3
- Optimized painting of rotated text.
Version 1.3.2
- Fixed wrong painting of selected and highlighted sections.
Version 1.3.1
- Fix bug: vertical size is always same as horizontal size.
Version 1.3
- Fix bug with extra column on first show of table view.
- New example: proxy model. It allows using HierarchicalHeaderView without subclassing QAbstractItemModel.
Version 1.2
- Fix potential crash after setModel call.
- Force header size recalculation. This fix some bugs with header size after setModel call.
Version 1.1
- Vertical header support.
Version 1.0.
- Initial release.
10 years ago
Version 1.3.3
- Optimized painting of rotated text.
Version 1.3.2
- Fixed wrong painting of selected and highlighted sections.
Version 1.3.1
- Fix bug: vertical size is always same as horizontal size.
Version 1.3
- Fix bug with extra column on first show of table view.
- New example: proxy model. It allows using HierarchicalHeaderView without subclassing QAbstractItemModel.
Version 1.2
- Fix potential crash after setModel call.
- Force header size recalculation. This fix some bugs with header size after setModel call.
Version 1.1
- Vertical header support.
Version 1.0.
- Initial release.
skebanga
4 years ago
Any idea on how to fix this?
Report
ArmanPrestige
5 years ago
Спасибо. Выручил
Report
mklein8791
6 years ago
Thanks for this great component !
I'm using it on Qt5.3.2
How to hide the root element of the header, or how to add multiple root element ?
Report
Sethien
6 years ago
I'm not 100% sure that this is what you want, but you should be able to add extra items in the header.(I used the example 2 project, and modified it a bit, so it works with QT 5.3.2) The example 2 project only uses the horizontal header and i added 8 items.
Hope it helps you with what you want, and otherwise let me know, maybe i can help you.
Project files:
https://www.dropbox.com/s/xqkmf6oa5r6lj8l/hv_example%28modified%29%20use%20example%202.zip?dl=0
Picture of the result:
http://imgur.com/TD0RSWP
Report
mklein8791
6 years ago
Well I found a workaround but it doesn't please me, so I will use your solution ;)
Report
Sethien
6 years ago
i'm using this application on qt 5.3.1 and i'm wondering if it's possible to hide the subcolumns of the horizontal header, but still make it possible for the root horizontal header element to span over multiple columns.
For now I sort of got a solution, I change the height of an item depending on the name/text. So if it's a subitem i set the height to 0, but the header will use the same height as when it contains the sub header column as well. So when hiding the subcolumns i want the height of the header to change as well.
So is there a better way to hide the subcolumns but keep the root column header spanning and change the height of the horizontal header to the height it is when only root items are used.
Report
Sethien
6 years ago
And i enabled the sort icon by adding:
if (isSortIndicatorShown() && sortIndicatorSection() == logicalInd)
opt.sortIndicator = (sortIndicatorOrder() == Qt::AscendingOrder) ? QStyleOptionHeader::SortDown : QStyleOptionHeader::SortUp;
to the styleOptionForCell funtion.
But when clicking on the horizontal header item that spans 2 columns the sortIndicator will only show for the whole button when i click on the right part. When i click on the left part the sortIndicator is shown half. Does anyone have a solution to make this working on only half the column item or both on the whole item?
see the pictures for more information:
http://imgur.com/FWRSUx7,CLKGpao,oPTpjVk
Report
Sethien
6 years ago
And i enabled the sort icon by adding:
if (isSortIndicatorShown() && sortIndicatorSection() == logicalInd)
opt.sortIndicator = (sortIndicatorOrder() == Qt::AscendingOrder) ? QStyleOptionHeader::SortDown : QStyleOptionHeader::SortUp;
to the styleOptionForCell funtion.
But when clicking on the horizontal header item that spans 2 columns the sortIndicator will only show for the whole button when i click on the right part. When i click on the left part the sortIndicator is shown half. Does anyone have a solution to make this working on only half the column item or both on the whole item?
see the pictures for more information:
http://imgur.com/FWRSUx7,CLKGpao,oPTpjVk
Report
Sethien
6 years ago
And i enabled the sort icon by adding:
if (isSortIndicatorShown() && sortIndicatorSection() == logicalInd)
opt.sortIndicator = (sortIndicatorOrder() == Qt::AscendingOrder) ? QStyleOptionHeader::SortDown : QStyleOptionHeader::SortUp;
to the styleOptionForCell funtion.
But when clicking on the horizontal header item that spans 2 columns the sortIndicator will only show for the whole button when i click on the right part. When i click on the left part the sortIndicator is shown half. Does anyone have a solution to make this working on only half the column item or both on the whole item?
see the pictures for more information:
http://imgur.com/FWRSUx7,CLKGpao,oPTpjVk
Report
Sethien
6 years ago
And i enabled the sort icon by adding:
if (isSortIndicatorShown() && sortIndicatorSection() == logicalInd)
opt.sortIndicator = (sortIndicatorOrder() == Qt::AscendingOrder) ? QStyleOptionHeader::SortDown : QStyleOptionHeader::SortUp;
to the styleOptionForCell funtion.
But when clicking on the horizontal header item that spans 2 columns the sortIndicator will only show for the whole button when i click on the right part. When i click on the left part the sortIndicator is shown half. Does anyone have a solution to make this working on only half the column item or both on the whole item?
see the pictures for more information:
http://imgur.com/FWRSUx7,CLKGpao,oPTpjVk
Report
Sethien
6 years ago
And i enabled the sort icon by adding:
if (isSortIndicatorShown() && sortIndicatorSection() == logicalInd)
opt.sortIndicator = (sortIndicatorOrder() == Qt::AscendingOrder) ? QStyleOptionHeader::SortDown : QStyleOptionHeader::SortUp;
to the styleOptionForCell funtion.
But when clicking on the horizontal header item that spans 2 columns the sortIndicator will only show for the whole button when i click on the right part. When i click on the left part the sortIndicator is shown half. Does anyone have a solution to make this working on only half the column item or both on the whole item?
see the pictures for more information:
http://imgur.com/FWRSUx7,CLKGpao,oPTpjVk
Report
Sethien
6 years ago
With my solution the header is twice as big than needed.
Report
Sethien
6 years ago
Report
RaideR2009
6 years ago
Report
chuong
7 years ago
Report
geracmos
7 years ago
I need to get a signal so that I could determine if a root cell or if a lower level cell has been clicked from the Headers and also get their QModelIndex. Something like QHeaderView::clicked(int) SIGNAL. Do you think that is possible? Any suggestions?
Report
DPB1956
7 years ago
HierarchicalHeaderView.cpp:382: undefined reference to `_imp___ZN11QHeaderViewD2Ev'
for function header:
HierarchicalHeaderView::HierarchicalHeaderView(Qt::Orientation orientation, QWidget *parent) :QHeaderView(orientation, parent), _pd(new private_data())
for instance. There are strange strings ie. “_imp___ZN11” and “D2Ev” embedded in the errors.
Has the widget been tested on Qt5 and is there an update that might work?
Report
Barmaglodd
7 years ago
Report
Diederikza
7 years ago
Only problem I have is when I call resizeColumnsToContents() on the TableView, and the first root title is longer than all the child cells, the table looks funny. http://dl.dropboxusercontent.com/u/22456079/share%20images/columnsMinWidth.png The root segment text (in the picture's case "Power port (W)") is only partially displayed.
I was expecting the root segment's content to also be taken in consideration when adjusting leaf width's columns.
Any tips for adding a "minimum root cell width" feature?
Report
Barmaglodd
7 years ago
Report
fralik
8 years ago
Is there a way one could resize sections from the code?
There is a resizeSection function in QTableView, but it has no effect on your widget.
Report
fralik
8 years ago
Report
alexeypertcev
8 years ago
Screenshot: http://ksu-ivt-nagruzka.googlecode.com/files/teachers_list.JPG
Report
verdrehung
9 years ago
Some screenshot: http://pix.academ.org/img/2011/12/01/08ba410347cad15b8fdb8fcbb4bf4635.png
Report
galoag
9 years ago
I extended your headerview allowing header sections to be clicked (setClickable(true)) - this worked just fine. Now I updated my Qt libs to the new version (4.7.3) resulting in the sectionClicked signal not triggered anymore. Usual QHeaderViews work just fine. Any ideas?
Report