【发布时间】:2019-12-19 10:48:39
【问题描述】:
我已经实现了一个“全部替换”功能,当按下“查找和替换”窗口上的全部替换按钮时会触发该功能。 但是,如果我尝试使用内置撤消功能撤消更改,则不会发生任何事情。
是否与我的文本编辑器在对话框窗口显示时没有聚焦有关?
def handle_replace_all():
old = find_win.line_edit_find.text() # text to replace
new = find_win.line_edit_replace.text() # new text
cursor = self.text_edit.textCursor()
cursor.beginEditBlock()
current_text = self.text_edit.toPlainText()
replaced_text = current_text.replace(old, new)
self.text_edit.setPlainText(replaced_text)
cursor.endEditBlock()
find_window.button_replace_all.clicked.connect(handle_replace_all)
为什么会这样? 感谢任何帮助。
【问题讨论】:
-
setPlainText 始终清除撤消/重做历史记录。
标签: python pyqt pyqt5 undo qtextedit