How do you suggest factoring it out since the widths might not be constant? The only thing I can think of is wrapping next_data in a separate function that will do the conversion, something like this:

    try:
        next_data = data.next
        if self._elide_mode != Qt.ElideNone:
            next_data = lambda: font_metrics.elidedText(data.next(), self._elide_mode, width-4)
        for row_height in row_heights:
            ...

But this is trickier when rendering the column headers since they could have variable width. What do you think?