Removing Separators from QHeaderView
-
Hello everybody.
I am using a QTreeview with multiple columns in one of our projects.
In this TreeView, some columns build a logical group and I just wondered if there is a way to eliminate the separator between those grouped columns (resizing them is already deactivated). Having the separator shown isn't a big problem, it just looks ugly ;)
Important is, that the separators shouldn't be removed for all columns, but only for specific ones...I guess the best solution would be to display the information of those grouped columns in a delegate and actually make it a single column, but this would cause quite a lot of refactoring work, which unfortunately is no option...
Does anyone know another way to do this?
-
You'd have to subclass QTreeView. I think, that you'll have to reimplement the drawRow method, but I'm not certain of that. Alternatively, it should be doable via the style. Both would probably require some digging into the Qt sources to find the best place to do this.
-
[quote author="Andre" date="1363290926"]You'd have to subclass QTreeView.[/quote]
It's only the header I want to remove the separators from, so I guess subclassing QHeaderView would be correct...
I already thought about doing so and overwriting drawSection(), but as I'm not that familiar with drawing, this wouldn't probably be less work than the delegate idea ;)I'd prefer a solution via stylesheets... but I guess that's not possible!?
-
Ah, sorry, yes. I thought you wanted to remove the separators in the view itself.
Using a delegate in QHeaderView is not possible.from the documentation:
[quote]Note: Each header renders the data for each section itself, and does not rely on a delegate. As a result, calling a header's setItemDelegate() function will have no effect.[/quote]Doing your own rendering shouldn't be all that hard though. You can rely on QStyle to do most of the hard work for you. You should be able to use QStyle::drawControl(CE_HeaderSection, ...) to do the rendering of a section of an item.
-
My idea was not to use a delegate in the headerview, but in the treeview, making the columns i want to group a single one -> then I'd not encounter the separator problem... but as I mentioned, this would cause too much refactoring work...
I'll have a look at QStyle...