how to imitate a link click in QTextBrowser
Actualy, i have different tabs. what I wanted to achieve is, - user clicked a link from tab 1 - and it will immediately display QTextBrowser in tab 2, at the html anchor i set.
Is there a way of doing this?
I've managed to switch tab by usi开发者_JAVA百科ng tabWidget.setCurrentWidget() now the question is, how to set the focus to the desired html anchor place of the QTextBrowser.
Thanks in advance.
Here's an example:
from tabwidget import Ui_MainWindow
import sys
from PyQt4 import QtGui, QtCore
class MyApp(QtGui.QMainWindow):
def __init__(self, parent=None):
QtGui.QWidget.__init__(self, parent)
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
QtCore.QObject.connect(self.ui.pushButton, QtCore.SIGNAL('clicked()'), self._show)
def _show(self):
self.ui.tabWidget.setCurrentWidget(self.ui.tab_2)
self.ui.textBrowser.setSource(QtCore.QUrl('text.html#anchor'))
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
mw = MyApp()
mw.show()
app.exec_()
精彩评论