I am displaying a TreeView with a custom sortfilterproxymodel (which takes another custom model as source) and a custom delegate (overwritten paint) to affect the display of each item.
However, I cannot get the header of the TreeView to show. I had a look at both the proxy and the normal model and both have their headerData() called and return the correct values. I do not explicitly hide the header. In fact, I explicitly show() the header of the TreeView and setHeaderHidden() to false.
What could cause the header not being shown?
Here is the paint() function of the delegate, as I suspect the mistake somewhere there:
//---------------------------------------------------------------------------------
void
MyDelegate::paint(QPainter* p_painter, const QStyleOptionViewItem& p_option, const QModelIndex& p_index) const
{
// Get a custom text
QString text = "";
// Code that changes the text variable, nothing fancy, no pre-mature return
// Left out for convenience
// Call painter methods for drawing
p_painter->save();
p_painter->setClipRect(p_option.rect);
drawBackground(p_painter, p_option, p_index);
drawDisplay(p_painter, p_option, p_option.rect, text);
drawFocus(p_painter, p_option, p_option.rect);
p_painter->restore();
}
If you wonder why I do all the painter stuff (save(), drawBackground, etc.) manually, it is because it seems to be the only way to change the displayed text inside the paint() function. At least the only one I could figure out. But I do not know if this has anything to do with the header not being shown in the view.
Edit: By now I tried to replace my own paint with the default one. The header is still not shown, so the paint() method seems to be innocent ;)
QTreeVeiewdelegate is only responsible for item drawing, not for header drawing. But try to replace all the code in yourMyDelegate::paint()with the call of defaultQItemDelegate::paint(p_painter, p_option, p_index). If the header is still hidden, the problem is definitely not in yourpaint().isHeaderHiddenproperty value.