[Qt-interest] How to have dynamic pixmap in a QHeaderView item
Andre Somers
andre at familiesomers.nl
Thu Aug 19 22:51:19 CEST 2010
Op 19-8-2010 20:40, David Boosalis schreef:
> I want to be able to display a pixmap in a item of a QTreeView's
> horizontal header. I have created my own Horizontal Header Class, and
> have tried to add my own Delegate to column 0 (the column where I want
> the pixmap to appear). The trouble is I never see the paint() method
> for this Delegate.
>
> At first I was setting the labels of the header with the model's
> method setHorizontalHeaderLabels(QStringList columnNames). I then
> went to the trouble of creating a QStandardItem for each column and
> adding it to the header with setHorizontalHeaderItem(col, headerItem).
>
> After both methods I would create my delegate and add it to the header
> with:
>
> MyHeaderDelegate *symbolDelegate = new MyHeaderDelegate(this);
> horHeader->setItemDelegateForColumn(0,myHeaderDelegate);
>
> I never see the debug message I have in the paint() method for
> MyHeaderDelegate.
>
> This is the approach I have used for things such as QTreeView and
> QTableView, but QHeaderView, even though it inherits from the same
> base class seems to be the bastard child. Any ideas on how to be
> able to paint pixmaps for a item in a horizontal header ? I want to be
> able to control if the pixmap gets painted. Is using a custom
> delegate the right way to go ?
QHeaderView does not use the delegates, you'll have to draw them
yourself directly. Sorry. From the documentation:
*Note:* Each header renders the data for each section itself, and
does not rely on a delegate. As a result, calling a
header'ssetItemDelegate <qabstractitemview.html#setItemDelegate>()
function will have no effect.
André
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100819/05fdd97e/attachment.html
More information about the Qt-interest-old
mailing list