PDA

View Full Version : tableview wordwrap header but not data columns



RolandHughes
27th October 2014, 23:18
I haven't went down the path of trying this yet. The documentation isn't clear so I thought I would ask before burning too much time on it. When deriving from the QAbstractTableView, is it possible to have wordwrap enabled for column headers but not data. The documentation for wordwrap just says "items" without indicating if they are header items or data items. Has anyone ever turned wordwrap on for the horizontal header but off for all data cells?

wysota
28th October 2014, 00:52
Eeem... There is no QAbstractTableView class, did you mean QAbstractTableModel or QTableView?

BTW. The header in the view is a separate widget, there are no "header items". The data for the headers is taken from implementation of QAbstractItemModel::headerData(). The layout of the header is implemented by QHeaderView. To override its look, reimplement paintSection().

jmalicke
28th October 2014, 02:05
I am struggling with the same issue. QHeaderView does not support word wrapping nor multiple lines. It's been quite frustrating and time consuming to deal with these limitations.

As a solution I tried feeding the header strings into a word wrap function that turns a longer string into multiple lines separated by a '\n' character. When I provide the multi-line string to the QHeaderView inside headerData(), it mostly works except for the following bug:

10705

Single line headers are all grey whereas this header has the white gap at the top. How would I go about fixing this color issue? If I can fix this issue then I'd say we have a working solution. I'd be happy to post the word wrap algorithm if it will help anybody.