0

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()
Malain
  • 3
  • 3
  • In what sense do you need the position: the screen coordinates, text index, or something else? You should post the minimum code that demonstrated what you are trying to do. – mdurant Oct 08 '14 at 22:34
  • Nobody has any idea? – Malain Oct 10 '14 at 11:19

1 Answers1

0

You need to pass the event up to the normal handler, because you've changed the normal behaviour. Add the following line at the end of the appropriate event handlers:

QTextBrowser.mousePressEvent(self, mouseEvent)

QTextBrowser.mouseReleaseEvent(self, mouseEvent)
mdurant
  • 27,272
  • 5
  • 45
  • 74