我有一个QTextBrowser,当我选择一部分文本在里面,我需要的位置开始和结束的选择。我在mousePressEvent和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()发布于 2014-10-10 13:37:37
您需要将事件传递给普通处理程序,因为您已经更改了正常行为。在适当的事件处理程序末尾添加以下行:
QTextBrowser.mousePressEvent(self, mouseEvent)
QTextBrowser.mouseReleaseEvent(self, mouseEvent)https://stackoverflow.com/questions/26262892
复制相似问题