HierarchicalHeaderView

Qt Widgets

Source i (link to git-repo or to original if based on someone elses unmodified work):

Add the source-code for this project on opencode.net

5
Become a Fan
6.8

Description:
Hierarchical header view for QTableView.
Header data is described by QAbstractItemModel. Text in cells of header can be rotated.
Last changelog:

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.


Ratings & Comments

50 Comments

skebanga

saving and restoring state doesn't work for this - they columns are always resized to fit their contents. Any idea on how to fix this?

ArmanPrestige

Thank you. Спасибо. Выручил

mklein8791

Hello, 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 ?

Sethien

Hello, 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

mklein8791

Thank you very much, that's what I needed. Well I found a workaround but it doesn't please me, so I will use your solution ;)

Sethien

Hello, 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.

Sethien

Picture to make it more clear: http://imgur.com/t7TI0JP With my solution the header is twice as big than needed.

Sethien

Ok i don't know what happend but it seems that my browser kept posting the same message, sorry for the extra posts

Sethien

Ok I fixed the height of the header items by reimplementing the: virtual QSize sizeHint() const; 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

Sethien

Ok I fixed the height of the header items by reimplementing the: virtual QSize sizeHint() const; 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

Sethien

Ok I fixed the height of the header items by reimplementing the: virtual QSize sizeHint() const; 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

Sethien

Ok I fixed the height of the header items by reimplementing the: virtual QSize sizeHint() const; 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

Sethien

Ok I fixed the height of the header items by reimplementing the: virtual QSize sizeHint() const; 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

RaideR2009

This is miracle, man ) thank you

chuong

A good app. I use it well, but it does't show sort indicator, or i have not find the right way?

geracmos

First of all thank you for the great App! 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?

DPB1956

Thanks for creating a great widget. This worked great using Qt 4 but on Qt 5.1 I’m getting many strange compile errors such as: 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?

Barmaglodd

Sorry, I did not tested it on Qt5. Qt5 is not stable to me to use in production. I'll try to test the widget.

Diederikza

I have used this widget in our project and it works nicely. 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?

Barmaglodd

Yes. It is a known bug. Feel free to fix it ;)

fralik

Thanks for the great widget! 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.

fralik

Sorry, it was my mistake. I should have resized the sections after I set a model.

alexeypertcev

I successfully used this class in a term paper for my university. Thank You. Screenshot: http://ksu-ivt-nagruzka.googlecode.com/files/teachers_list.JPG

verdrehung

We successfully used this class in one of our projects. Thank you! Some screenshot: http://pix.academ.org/img/2011/12/01/08ba410347cad15b8fdb8fcbb4bf4635.png

galoag

Hi, great work! 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?

Pling
0 Affiliates
Details
license
version 1.3.3
updated
added
downloads 24h 1
mediaviews 24h 0
pageviews 24h 4

Other Qt Widgets:

Widget Virtual Keyboard
embitel
last update date: 15 years ago

Score 5.3

Widget Marquee Label
embitel
last update date: 15 years ago

Score 6.1

Widget Color Picker
embitel
last update date: 15 years ago

Score 4.7

QtitanDataGrid advanced Grid for Qt
BigZ1
last update date: 7 years ago

Score 5.7

QtitanRibbon Microsoft RibbonUI and Office Styles for Qt
BigZ1
last update date: 7 years ago

Score 5.2

Q7TaskBar
QDevelopper
last update date: 13 years ago

Score 6.1