QTextBrowser
内部のテキストの一部を選択すると、選択範囲の開始位置と終了位置が必要になります。私は and でそれを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()