[PyQt] vertical alignment of richtext in a table view
Wolfgang Rohdewald
wolfgang at rohdewald.de
Sun Sep 5 09:55:04 BST 2010
Hi,
in Mark Summerfields book "Rapid GUI programming with Python
and QT", there is an example on page 485 with a table column
having a delegate that displays richtext. In the book,
the text in this column has a vertical alignment in the middle
of the cells, just like the other columns.
but if I execute that example (from the downloadable source:
chap16/carhirelog.pyw), the rich text is vertically not
in the middle but above. How can I make it align vertically
just like a normal column?
His book has another such table chap14, page 436 /
ships_delegate.pyw.
Here, both the image in the book and the executable show
the same wrong vertical alignment.
BTW interesting things happen if the column with richtext
is resized to a minimum: the delegate draws outside of its
available horizontal space, showing text to the right of
the rightmost column.
(using pyqt 4.7.3 with qt4-4.7.0-rc1)
this is the paint of the delegate:
def paint(self, painter, option, index):
text = index.model().data(index, Qt.DisplayRole).toString()
palette = QApplication.palette()
document = QTextDocument()
document.setDefaultFont(option.font)
if option.state & QStyle.State_Selected:
document.setHtml(QString("<font color=%1>%2</font>") \
.arg(palette.highlightedText().color().name()) \
.arg(text))
else:
document.setHtml(text)
painter.save()
color = palette.highlight().color() \
if option.state & QStyle.State_Selected \
else QColor(index.model().data(index,
Qt.BackgroundColorRole))
painter.fillRect(option.rect, color)
painter.translate(option.rect.x(), option.rect.y())
document.drawContents(painter)
painter.restore()
--
Wolfgang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20100905/a2b81add/attachment.html>
More information about the PyQt
mailing list