pyqt文本编辑是否有字体上划线属性

Does pyqt text edit has a font overline property

我知道 PyQt QTextChar 格式有字体上划线 属性 但 pyqt textedit

只有字体斜体、粗体和 underline.Does textEdit 字体上划线存在??

那么语法是什么?

答案是肯定的,

尝试这样的事情:

import sys
from PyQt5.QtWidgets import QApplication
from PyQt5.QtWidgets import QTextEdit
from PyQt5.QtWidgets import QVBoxLayout
from PyQt5.QtWidgets import QWidget


class Widget(QWidget):

    def __init__(self):
        super(Widget, self).__init__()
        self.text_edit = QTextEdit("Overlining...")
        self.text_edit.setStyleSheet("""
            text-decoration: overline;
        """)
        self.layout = QVBoxLayout()
        self.setLayout(self.layout)
        self.layout.addWidget(self.text_edit)



if __name__ == '__main__':
    app = QApplication(sys.argv)
    wid = Widget()
    wid.show()
    sys.exit(app.exec_())

你还有很多其他的properties and examples你可以看看


还有其他一些方法,其中之一是不使用样式表,而是可以设置 "html" properties of its qdocument,如下所示:

self.text_edit = QTextEdit()
personalized_document = QTextDocument()
personalized_document.set...#set all you need for example the overline you need.
self.text_edit.setDocument(personalized_document)