[PyQt] vertical alignment of richtext in a table view
Wolfgang Rohdewald
wolfgang at rohdewald.de
Tue Sep 7 00:37:45 BST 2010
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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100907/d2709c13/attachment.html>
More information about the PyQt
mailing list