On Montag 06 September 2010, Mark Summerfield wrote: > I'm tending to use a differnt approach for rich text delegates > nowadays. Instead of using a QTextDocument, I store a > class-level QLabel, something like this:
your solution certainly looks cleaner than my temporary fix (document.setDocumentMargin(7.0)), and it solves the problem of painting outside of the field. but it does not quite work for me. Your untested example leaves the fields blank, it seems I have to give the renderer a position. Using view.pos() + option.rect.topLeft(), labels are still too far up and left. The magical offset (3,25) puts them all in the right place. How can I compute the correct place instead? class RichTextColumnDelegate(QtGui.QItemDelegate): label = QtGui.QLabel() def __init__(self, parent=None): super(RichTextColumnDelegate, self).__init__(parent) def paint(self, painter, option, index): text = index.model().data(index, QtCore.Qt.DisplayRole).toString() self.label.setText(text) self.label.setFixedSize(option.rect.size()) view = self.parent().parent().view topLeft = view.pos() + option.rect.topLeft() + QtCore.QPoint(3, 25) self.label.render(painter, topLeft) def sizeHint(self,option,index): # still uses QTextDocument as in your book -- Wolfgang
_______________________________________________ PyQt mailing list PyQt@riverbankcomputing.com http://www.riverbankcomputing.com/mailman/listinfo/pyqt