I have a QTextBrowser
and when I select a part of the text inside, I need the position of the start and the end of the selection. I do that with mousePressEvent
and mouseReleaseEvent
and it works, but the highlight selection (dark blue) doesn't appear. Why? So I can't see what I selected.
I tried with the signal selectionChanged
but the problem is that signal is called each time I select the text and not when I release the mouse and the end of the selection.
Any suggestion?
Thanks!
Edit:
This works like I want:
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()
I need the position of the click. Here: self.mousePress and self.mouseRelease. But when I select the text in my QTextBrowser, the highlight doesn't appear. I hope I am more clear...
Edit 2:
Or this:
self.browserInput.selectionChanged.connect(self.position)
def position(self):
start = self.browserInput.textCursor().selectionStart()
end = self.browserInput.textCursor().selectionEnd()