richtext - Drop caps in Qt rich text -
i want render png image , text, starts drop cap. afaik, can render rich text qtextdocument::drawcontents
, how can add drop cap surrounded regular size text?
the upper part of image below qtextbrowser
, lower 1 rendered transparent qpixmap
placed on qlabel
:
i haven't tried render additional pictures yet question stated, shouldn't hard.
textdocument = qtgui.qtextdocument(self) #self.t.setdocument(textdocument) textdocument.setdefaultfont(qtgui.qfont("times new roman", 12)) textdocument.setdefaultstylesheet(".firstcharacter {" "float: left;" "color: #903;" "font-size: 72px;" "font-family: monotype corsiva;" "margin-top: -16px;" "margin-bottom: -16px;" "margin-right: 4px;" "}") textdocument.sethtml('<p>' '<table class="firstcharacter"><tr><td>l</td></tr></table>' 'ipsum dolor sit amet, consectetur adipiscing elit. mauris ' 'tristique lobortis orci ac lacinia. fusce eu purus eget ' 'diam vehicula auctor nec eu elit. morbi consequat facilisis ' 'orci vel malesuada. donec ultrices molestie sollicitudin. ' 'aliquam pharetra libero enim. donec et suscipit massa. ' 'donec dui odio, dignissim non sodales et, tincidunt sapien. ' 'phasellus elit nibh, adipiscing sed blandit vel, interdum et arcu.' '</p>') textdocument.settextwidth(400) img = qtgui.qimage(textdocument.size().tosize(), qtgui.qimage.format_argb32_premultiplied) img.fill(qtcore.qt.transparent) #img.fill(0xffffffff) p = qtgui.qpainter(img) p.translate(0, 0) #makes drop cap smoother textdocument.drawcontents(p) p.end() self.pic.setpixmap(qtgui.qpixmap.fromimage(img)) img.save(r"d:\testimg.png")
references:
Comments
Post a Comment