所以没有人想使用我正在运行的示例,这里只是更改字体的代码。尽管我认为应该这样做,但它不能按原样工作。如果您取消注释注释行,它会起作用。但为什么?这不应该是默认行为吗?
def changeFont(self):
cur=self.textedit.textCursor()
if cur.hasSelection():
begin=cur.anchor()
end=cur.position()
if begin>end:
helper=end
end=begin
begin=helper
else:
cur.select(QTextCursor.Document)
begin=0
plainText=self.textedit.toPlainText()
end=len(plainText)
for i in range(begin,end):
cur.setPosition(i)
cur.movePosition(QTextCursor.Right, QTextCursor.KeepAnchor)
fmt=cur.charFormat()
#pointSize=fmt.fontPointSize()
#if fmt.fontUnderline():
# underline=True
#else:
# underline=False
#if fmt.fontItalic():
# italic=True
#else:
# italic=False
#if fmt.fontWeight()==75:
# bold=True
#else:
# bold=False
#if fmt.fontStrikeOut():
# strikeOut=True
#else:
# strikeOut=False
fmt.setFont(QFont(self.font))
#if underline:
# fmt.setFontUnderline(True)
#if italic:
# fmt.setFontItalic(True)
#if bold:
# fmt.setFontWeight(75)
#if strikeOut:
# fmt.setFontStrikeOut(True)
#fmt.setFontPointSize(pointSize)
cur.mergeCharFormat(fmt)