首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >PyQt4 QTextCursor更改可选字符

PyQt4 QTextCursor更改可选字符
EN

Stack Overflow用户
提问于 2015-05-22 22:23:42
回答 1查看 340关注 0票数 0

如何更改QTextCursor的可选字符,如添加点?例如,在QPlainTextEdit中输入"MyClass“。

代码语言:javascript
复制
tc = self.textCursor()
tc.select(QtGui.QTextCursor.WordUnderCursor)
return tc.selectedText()

将返回"MyClass",但输入“MyClass”。将返回一个空的Qstring!问题仍然存在,输入"MyClass.myMeth“将只返回"myMeth",但我需要"MyClass.myMeth”:/谢谢

EN

回答 1

Stack Overflow用户

发布于 2015-05-24 14:45:27

好的,我找到了一个解决方案,将对WordUnderCursor的调用替换为:

代码语言:javascript
复制
def textUnderCursor(self):
        tc = self.textCursor()
        isStartOfWord = False
        if tc.atStart() or (tc.positionInBlock() == 0):
            isStartOfWord = True
        while not isStartOfWord:
            tc.movePosition(QtGui.QTextCursor.PreviousCharacter, QtGui.QTextCursor.KeepAnchor)
            if tc.atStart() or (tc.positionInBlock() == 0):
                isStartOfWord = True
            elif QtCore.QChar(tc.selectedText()[0]).isSpace():
                isStartOfWord = True
        return tc.selectedText().trimmed()
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30399241

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档