Here is a good PyQt Tutorial to start with.
To get a toolbar you have to create a MainWindow which will have a toolbar and contain your browser window as your central widget. To add items to the toolbar you first have to create actions and then add those actions to the toolbar. Actions can be connected with a function that will be executed when the action is triggered.
Here is a working snippet:
import sys
from PySide import QtCore, QtGui, QtWebKit
class MainWindow(QtGui.QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
# Create an exit action
exitAction = QtGui.QAction('Load Yahoo', self)
# Optionally you can assign an icon to the action
# exitAction = QtGui.QAction(QtGui.QIcon('exit24.png'), 'Exit', self)
exitAction.setShortcut('Ctrl+Q') # set the shortcut
# Connect the action with a custom function
exitAction.triggered.connect(self.load_yahoo)
# Create the toolbar and add the action
self.toolbar = self.addToolBar('Exit')
self.toolbar.addAction(exitAction)
# Setup the size and title of the main window
self.resize(650, 750)
self.setWindowTitle('Browser')
# Create the web widget and set it as the central widget.
self.web = QtWebKit.QWebView(self)
self.web.load(QtCore.QUrl('http://google.com'))
self.setCentralWidget(self.web)
def load_yahoo(self):
self.web.load(QtCore.QUrl('http://yahoo.com'))
app = QtGui.QApplication(sys.argv)
main_window = MainWindow()
main_window.show()
sys.exit(app.exec_())