I have a QTreeWidget object on a form and I'm using an item delegate to allow me to override how the columns are displayed.

I want my second column to be a progress bar so in the item delegate's paint() method I override the option passed in with a new QStyleOptionProgressBar (as is the method used in the torrent example).

This all works well but from inside that paint() method I want to be able to access the relevant QTreeWidgetItem that it is painting and I can't figure out how to do it.

There are three objects passed in: a QPainter, a QStyleOptionViewItem and a QModelIndex.

In the torrent example it does something similar by using the row from the QModelIndex but I can't do that as I have rows within rows so there can be many instances of row 1, for example. Plus, it seems like a bit of a hack anyway.

There must be a way to do this but I've been reading the docs and looking at examples for a couple of hours and I can't figure it out.

Please help.