lionel319
lionel319

Reputation: 1256

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 using tabWidget.setCurrentWidget() now the question is, how to set the focus to the desired html anchor place of the QTextBrowser.

Thanks in advance.

Upvotes: -1

Views: 1392

Answers (1)

Jade Amora Lua
Jade Amora Lua

Reputation: 312

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_()

Upvotes: 2

Related Questions