Это, вероятно, регрессия между Qt4.7 и Qt4.8. Каждый абзац должен быть на отдельной строке, но на 4.8 он сломан. Вы знаете о каком-то обходном пути?регрессия в Qt между 4.7 и 4.8
#!/usr/bin/env python3
import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import *
class CustomLabel(QLabel):
def __init__(self, text):
super(CustomLabel, self).__init__(text)
self._text = text
def paintEvent(self, event):
brect = QRect() #Qt.rect()
painter = QPainter(self)
painter.fillRect(brect, Qt.transparent)
doc = QTextDocument(self)
stylesheet = "*{color: " + painter.pen().color().name() + "; line-height:0.3; margin:0; padding:0;}"
doc.setDefaultStyleSheet(stylesheet)
doc.setUndoRedoEnabled(False)
doc.setHtml(self._text)
doc.setUseDesignMetrics(True)
doc.drawContents(painter, QRectF())
print(doc.toHtml())
print(doc.toPlainText())
app = QApplication(sys.argv)
label = CustomLabel("<p><font style=\"font-size: 9px;\" color=\"#fffe51\">Text 2</font></p><p><font size=\"9px\" color=\"#aaaaaa\">Text 3</font></p>")
label.show()
label.resize(100, 100)
sys.exit(app.exec_())
Спасибо, кажется, что удаление высота строки фиксированной вопрос – Miso