我有一个QTextBrowser
,当我选择里面的一部分文本时,我需要选择开始和结束的位置。我用mousePressEvent
and来做,mouseReleaseEvent
它可以工作,但是高亮选择(深蓝色)没有出现。为什么?所以我看不到我选择了什么。
我尝试使用信号selectionChanged
,但问题是每次选择文本时都会调用信号,而不是在释放鼠标和选择结束时调用。
有什么建议吗?
谢谢!
编辑:
这就像我想要的那样工作:
class MyBrowser(QTextBrowser):
def __init__(self, parent=None, textableAnnotate=None):
super(MyBrowser, self).__init__(parent)
self.textableAnnotate = textableAnnotate
self.mousePress = 0
self.mouseRelease = 0
def mousePressEvent(self, mouseEvent):
self.mousePress = self.cursorForPosition(mouseEvent.pos()).position()
def mouseReleaseEvent(self, mouseEvent):
self.mouseRelease = self.cursorForPosition(mouseEvent.pos()).position()
我需要点击的位置。这里:self.mousePress 和 self.mouseRelease。但是当我在 QTextBrowser 中选择文本时,突出显示不会出现。我希望我更清楚...
编辑2:
或这个:
self.browserInput.selectionChanged.connect(self.position)
def position(self):
start = self.browserInput.textCursor().selectionStart()
end = self.browserInput.textCursor().selectionEnd()