You can use the selectionChanged signal to trigger the function, and then retrieve the selected text via the textCursor. The processed text can be displayed by using either setPlainText, or, if you want to use markup, setHtml. But note that QTextBrowser
only supports a limited subset of html/css.
Here's a demo script that shows how to put it all together:
from PySide import QtCore, QtGui
class Window(QtGui.QWidget):
def __init__(self):
QtGui.QWidget.__init__(self)
self.edit = QtGui.QTextEdit(self)
self.edit.selectionChanged.connect(self.handleSelectionChanged)
self.browser = QtGui.QTextBrowser(self)
layout = QtGui.QHBoxLayout(self)
layout.addWidget(self.edit)
layout.addWidget(self.browser)
def handleSelectionChanged(self):
text = self.edit.textCursor().selectedText()
# process text here...
self.browser.setPlainText(text)
if __name__ == '__main__':
import sys
app = QtGui.QApplication(sys.argv)
window = Window()
window.setGeometry(500, 300, 600, 300)
window.show()
sys.exit(app.exec_())