Set delegate for QTreeWidget header

2019-08-06 11:52发布

问题:

I need to set delegate for QTreeWidget header or make it working with HTML tags using other ways.

I set a delegate for QTreeWidget items using

ui->tree->setItemDelegate(delegate);

and it works.

But setting a delegate to the header does not work :

ui->tree->header()->setItemDelegate(delegate);

回答1:

It won't work and it's documented here http://qt-project.org/doc/qt-4.8/qheaderview.html#appearance

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.