我有一个简单的编辑器,我正在尝试移植到 PyQt6,但遇到了文档修改消息的问题。它在 PyQt5 中运行良好,但在 PyQt6 中生成'TypeError: unable to convert a QVariant back to a Python object'
消息。
# from PyQt6 import QtWidgets
# from PyQt6.Qsci import QsciScintilla
from PyQt5 import QtWidgets
from PyQt5.Qsci import QsciScintilla
class SimplePythonEditor(QsciScintilla):
def __init__(self, parent=None):
super().__init__(parent)
self.SCN_MODIFIED.connect(self._modified)
# The current documentation https://www.scintilla.org/ScintillaDoc.html#SCN_MODIFIED shows a slightly different set of arguments and order.
# def _modified(self, modificationType, position, length, linesAdded, text, line, foldLevelNow, foldLevelPrev):
def _modified(self, position, modificationType, text, length, linesAdded, line, foldLevelNow, foldLevelPrev, token, annotationLinesAdded):
print(f'_modified {modificationType=}, {position=}, {length=}, {linesAdded=}, {text=}, {line=}, {foldLevelNow=}, {foldLevelPrev=}, {token=}, {annotationLinesAdded=}')
if __name__ == "__main__":
app = QtWidgets.QApplication([])
editor = SimplePythonEditor()
editor.show()
app.exec()
运行代码并在 PyQt5 中输入 abc 会生成以下输出
_modified modificationType=1048576, position=0, length=1, linesAdded=0, text=None, line=0, foldLevelNow=0, foldLevelPrev=0, token=0, annotationLinesAdded=0
_modified modificationType=1040, position=0, length=1, linesAdded=0, text=None, line=0, foldLevelNow=0, foldLevelPrev=0, token=0, annotationLinesAdded=0
_modified modificationType=8209, position=0, length=1, linesAdded=0, text=b'a', line=0, foldLevelNow=0, foldLevelPrev=0, token=0, annotationLinesAdded=0
_modified modificationType=1048576, position=1, length=1, linesAdded=0, text=None, line=0, foldLevelNow=0, foldLevelPrev=0, token=0, annotationLinesAdded=0
_modified modificationType=1040, position=1, length=1, linesAdded=0, text=None, line=0, foldLevelNow=0, foldLevelPrev=0, token=0, annotationLinesAdded=0
_modified modificationType=17, position=1, length=1, linesAdded=0, text=b'b', line=0, foldLevelNow=0, foldLevelPrev=0, token=0, annotationLinesAdded=0
_modified modificationType=1048576, position=2, length=1, linesAdded=0, text=None, line=0, foldLevelNow=0, foldLevelPrev=0, token=0, annotationLinesAdded=0
_modified modificationType=1040, position=2, length=1, linesAdded=0, text=None, line=0, foldLevelNow=0, foldLevelPrev=0, token=0, annotationLinesAdded=0
_modified modificationType=17, position=2, length=1, linesAdded=0, text=b'c', line=0, foldLevelNow=0, foldLevelPrev=0, token=0, annotationLinesAdded=0
我在 linux 我使用的软件包版本
PyQt5==5.15.4
PyQt5-Qt5==5.15.2
QScintilla==2.13.0
PyQt6==6.1.1
PyQt6-Qt6==6.1.2
PyQt6-QScintilla==2.13.0