[PyKDE] Implementing QSimpleRichText

Eron Lloyd elloyd at lancaster.lib.pa.us
Sun Aug 15 21:09:19 BST 2004


Hey thanks. I thought about the idea of creating pixmaps, but I would really 
like to understand the intrinsics of QPainter and friends, as I'm in the 
process of developing some pretty complicated UI stuff and would like to take 
full advantage of the drawing primatives. Perhaps this is something to ask 
for in Qt4 (as part of the Interview framework, perhaps).

Regards,

Eron

On Friday 13 August 2004 1:58 pm, David Boddie wrote:
> On Thu, 12 Aug 2004 21:02:46, Eron Lloyd wrote:
> >Does anybody have an example of how to implement rich text inside of a
> >QListViewItem? I can't wrap my head around the C++ examples I've found
> > enough to translate what needs to be done. It seems a little more tricky
> > when not implemented inside a QWidget...
>
> You could probably start from the example given at
>
>     http://doc.trolltech.com/qq/qq08-fancy-list-view.html
>
> Something simple like the following might be enough, but you may want to
> think about how the items are painted.
>
> Good luck,
>
> David
>
>
> #!/usr/bin/env python
>
> import sys
>
> from qt import QApplication, QBrush, QLabel, QListView, QListViewItem, \
>                QPixmap, Qt
>
> class RichTextItem(QListViewItem):
>
>     def __init__(self, parent, previous = None):
>
>         QListViewItem.__init__(self, parent, previous)
>         self.label = QLabel(None)
>
>     def paintCell(self, painter, colorGroup, column, width, alignment):
>
>         painter.save()
>         painter.fillRect(0, 0, width, self.height(), QBrush(Qt.white))
>         self.label.setText(self.text(column))
>         self.label.resize(width, self.height())
>         pixmap = QPixmap.grabWidget(self.label, 0, 0, width, self.height())
>         painter.drawPixmap(0, 0, pixmap)
>         painter.restore()
>
> example_text = """<h1>My list items</h1>
> <b>A bold item</b>
> <i>An italic item</i>
> Some <i>mixed</i> <b>text</b>"""
>
> if __name__ == "__main__":
>
>     app = QApplication(sys.argv)
>     list_view = QListView()
>     list_view.addColumn("Label")
>     list_view.setSorting(-1)
>
>     previous = None
>     for line in example_text.split("\n"):
>
>         list_item = RichTextItem(list_view, previous)
>         list_item.setText(0, line)
>         previous = list_item
>
>     list_view.show()
>
>     app.setMainWidget(list_view)
>     sys.exit(app.exec_loop())
>
>
>
> ___________________________________________________________
> $0 Web Hosting with up to 120MB web space, 1000 MB Transfer
> 10 Personalized POP and Web E-mail Accounts, and much more.
> Signup at www.doteasy.com
>
> ---
> [This E-mail scanned for viruses by Declude Virus]

-- 
Eron Lloyd
Technology Coordinator
Lancaster County Library
elloyd at lancaster.lib.pa.us
Phone: 717-239-2116
Fax: 717-394-3083
---
[This E-mail scanned for viruses by Declude Virus]




More information about the PyQt mailing list