【问题标题】:QtWidgets.QTextEdit.textCursor().movePosition(); how to define the exact number of characters?QtWidgets.QTextEdit.textCursor().movePosition();如何定义确切的字符数?
【发布时间】:2021-06-11 06:03:15
【问题描述】:

一种在 QTextEdit has already been proposed in stackoverflow by vicent 中查找子字符串并突出显示它的方法。

这是一种优雅而有效的方法。但是在使用时:

cursor.movePosition(QtGui.QTextCursor.EndOfWord, 1)

突出显示到检测到子字符串的单词的末尾。

我正在寻找一种方法来定义确切的字符数。像这样的东西(不起作用!):

cursor.movePosition(len(pattern), 1)

仅突出显示子字符串。

【问题讨论】:

    标签: python pyqt qtextedit


    【解决方案1】:

    使用带有QTextCursor::Right的for循环:

    for _ in pattern:
        cursor.movePosition(QtGui.QTextCursor.Right, 1)
    

    【讨论】:

    • 正是我需要的!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-10
    • 1970-01-01
    • 1970-01-01
    • 2014-03-15
    • 2015-05-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多