答案 0 :(得分:1)
下方图片的上半部分为QTextBrowser
,下方是放置在QPixmap
上的呈现透明QLabel
:
我的问题尚未尝试渲染任何其他图片,但不应该那么难。
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 a 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")
参考文献: