Skip to content

Instantly share code, notes, and snippets.

@albop
Created Apr 9, 2014
Embed
What would you like to do?
Browser with tabs
#!/usr/bin/python
# -*- coding: utf-8 -*-
from __future__ import print_function
import sys
from PySide.QtCore import *
from PySide.QtGui import *
from PySide import QtGui
from PySide.QtWebKit import *
from PySide import QtWebKit
class Form(QDialog):
def __init__(self, parent=None):
super(Form, self).__init__(parent)
self.tabWidget = QtGui.QTabWidget()
web = QWebView()
web.setUrl(QUrl("http://www.google.fr/"))
self.webviews = [web]
# web.reload()
self.button = QPushButton("Show Greetings")
self.url = QTextEdit()
layout = QVBoxLayout()
layout.addWidget(self.tabWidget)
layout.addWidget(self.button)
layout.addWidget(self.url)
self.setLayout(layout)
self.tabWidget.addTab(self.webviews[0], "General")
self.setWindowTitle("My Form")
self.button.clicked.connect(self.load_url)
web.page().setLinkDelegationPolicy(QtWebKit.QWebPage.DelegateAllLinks)
web.linkClicked.connect(lambda x: self.open_link(x))
def open_link(self, arg__1):
web = QWebView()
self.webviews.append(web)
self.tabWidget.addTab(web, str(arg__1))
web.setUrl(QUrl(arg__1))
print("Clicked")
def load_url(self):
txt = self.url.toPlainText()
self.webviews[0].setUrl(QUrl(txt))
if __name__ == '__main__':
# Create the Qt Application
app = QApplication(sys.argv)
# Create and show the form
form = Form()
form.show()
# Run the main Qt loop
sys.exit(app.exec_())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment