Skip to content

Instantly share code, notes, and snippets.

@albop
Created April 9, 2014 15:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save albop/10281951 to your computer and use it in GitHub Desktop.
Save albop/10281951 to your computer and use it in GitHub Desktop.
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