Python 2.7 pyqt文本编辑是否具有字体上划线属性
我知道PyQt-QTextChar格式有一个字体上划线属性,但PyQt-textedit 只有斜体、粗体和下划线。文本编辑字体是否存在Python 2.7 pyqt文本编辑是否具有字体上划线属性,python-2.7,python-3.x,pyqt,pyqt4,pyqt5,Python 2.7,Python 3.x,Pyqt,Pyqt4,Pyqt5,我知道PyQt-QTextChar格式有一个字体上划线属性,但PyQt-textedit 只有斜体、粗体和下划线。文本编辑字体是否存在 那么语法是什么?答案是肯定的 试着这样做: import sys from PyQt5.QtWidgets import QApplication from PyQt5.QtWidgets import QTextEdit from PyQt5.QtWidgets import QVBoxLayout from PyQt5.QtWidgets import QW
那么语法是什么?答案是肯定的 试着这样做:
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_())
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)
你有很多其他的,你可以看看
还有其他一些方法,其中一种是不使用样式表,您可以设置its的“html”,如下所示:
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_())
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)
还有一件事。如何获取样式表的值。我的意思是,在QTextchar格式中,您可以执行类似打印格式的操作。fontItalic()我不知道它是否正是您想要的,但在设置样式表后,您可以使用
self.text\u edit.stylesheet()
访问它所具有的属性,它将返回一个包含这些属性的字符串。或者您可以制作类似于self.text\u edit.font()
的东西,它将返回一个QFont
对象,从那里您可以拥有pointSize
,以及QFont
中的许多其他属性。您不仅可以访问它的QFont()
,还可以访问它的QColor
,QBrush
,以及其他许多功能。。这有帮助吗?还是不是你想弄明白的?