您可以使用
selectionChanged
信号触发函数,然后通过
textCursor
。可以使用
setPlainText
,或者,如果要使用标记,
setHtml
。但请注意
QTextBrowser
仅支持
limited subset
html/css的。
下面是一个演示脚本,演示如何将所有内容组合在一起:
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_())