わかりました、ここで一種の答えを見つけました: Word Wrap with HTML? QTableView とデリゲート
また、テキストを html に変換し、html の書式設定を可能にします (私もそれが必要でした) が、ワードラップを使用して単純なテキストを表示するように簡単に変換できると思います。
このスニペットは基本的に、QStyledItemDelegate を使用して、その場でコンテンツやコンテンツのフォーマットを変更したい人向けです。
options = QtGui.QStyleOptionViewItemV4(option)
self.initStyleOption(options, index)
painter.save()
doc = QtGui.QTextDocument()
text_option = QtGui.QTextOption(doc.defaultTextOption())
text_option.setWrapMode(QtGui.QTextOption.WordWrap)
doc.setDefaultTextOption(text_option)
# Modify the text here. Ex:
# options.text += "<br><br>"
doc.setHtml(options.text)
doc.setTextWidth(options.rect.width())
options.text = ""
options.widget.style().drawControl(QtGui.QStyle.CE_ItemViewItem, options, painter)
# Center the text vertically
height = int(doc.documentLayout().documentSize().height())
painter.translate(options.rect.left(), options.rect.top() + options.rect.height() / 2 - height / 2)
clip = QtCore.QRectF(0, 0, options.rect.width(), options.rect.height())
doc.drawContents(painter, clip)
painter.restore()