[PyQt] vertical alignment of richtext in a table view

Mark Summerfield list at qtrac.plus.com
Sun Dec 19 08:18:45 GMT 2010


Hi Wolfgang,

On Sat, 18 Dec 2010 18:56:36 +0100
Wolfgang Rohdewald <wolfgang at rohdewald.de> wrote:
> On Dienstag 07 September 2010, Mark Summerfield wrote:
> > > > The offset you need might be made up of the
> > > > option.decorationSize's width; not sure about the height
> > > > offset.
> > >
> > > 
> > >
> > > decorationSize is (16,16) - that does not explain it.
> > 
> > Then I'm not sure. Could try experimenting with the label's
> > indent, margin, and frameWidth.
> 
> now I found the problem.
> 
> This misplaces the text:
> 
> class RichTextColumnDelegate(QStyledItemDelegate):
>     label = QLabel()
>     def paint(self, painter, option, index):
> 		...
>         self.label.render(painter, option.rect.topLeft())
> 
> I have to do:
>         painter.save()
>         painter.translate(option.rect.topLeft())
>         self.label.render(painter)
>         painter.restore()

Yes, I just checked with the PyQt book's examples and that's almost the
same as what I do:

    def paint(self, painter, option, index):
        ...
        painter.save()
        ...
        painter.translate(option.rect.x(), option.rect.y())
        ...
        painter.restore()


-- 
Mark Summerfield, Qtrac Ltd, www.qtrac.eu
    C++, Python, Qt, PyQt - training and consultancy
        "Programming in Python 3" - ISBN 0321680561
            http://www.qtrac.eu/py3book.html


More information about the PyQt mailing list