【发布时间】:2018-04-11 07:01:44
【问题描述】:
我有一个QTextBrowser,我想选择里面的一部分文本,我需要选择开始和结束的位置。我想用mousePressEvent 和mouseReleaseEvent 做到这一点。这是我的代码,
class MainWindow(QMainWindow, TeamInsight.Ui_MainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.setupUi(self)
def set_text(self):
self.textBrowser.setText('test strings are here')
textBrowser 在 MainWindow 中。如何为 textBrowser 中的文本实现 mousePressEvent 和 mouseReleaseEvent
【问题讨论】:
-
QTextBrowser 已经实现了鼠标文本选择。为什么又要实现呢?
-
我想在选定的字符串位置等于特定值时触发另一种方法。
-
好的,我明白了,当你说我需要选择的开始和结束的位置时,你的意思是什么类型的单位,以像素为单位?跨度>
-
我的意思是选择的起始字符和结束字符的位置。例如:假设字符串是 'test' 。字母“e”的位置是 1。“s”的位置是 2。
-
self.browserInput.selectionChanged.connect(self.position) def position(self): start = self.browserInput.textCursor().selectionStart() end = self.browserInput.textCursor().selectionEnd()这段代码给了我一个部分解决方案。但是当我进行选择时它会给出多个值。
标签: python pyqt pyqt5 qtextbrowser