python - How do add a toolbar on the browser example of PySide? -


#!/usr/bin/env python #-*- coding:utf-8 -*- import sys pyside.qtcore import * pyside.qtgui import * pyside.qtwebkit import * pyside.qthelp import * pyside.qtnetwork import *  app = qapplication(sys.argv)  web = qwebview() web.load(qurl("http://google.com")) web.show() web.resize(650, 750) q_pixmap = qpixmap('icon.ico') q_icon = qicon(q_pixmap) qapplication.setwindowicon(q_icon) web.setwindowtitle('browser') sys.exit(app.exec_()) 

how add toolbar on 2 buttons: 1 called 'url 1' , other 'url 2' if click on it open url. compare list favorite websites if know mean.

thanks!

here pyqt tutorial start with.

to toolbar have create mainwindow have toolbar , contain browser window central widget. add items toolbar first have create actions , add actions toolbar. actions can connected function executed when action triggered.

here working snippet:

import sys pyside import qtcore, qtgui, qtwebkit  class mainwindow(qtgui.qmainwindow):     def __init__(self):         super(mainwindow, self).__init__()         # create exit action         exitaction = qtgui.qaction('load yahoo', self)         # optionally can assign icon action         # exitaction = qtgui.qaction(qtgui.qicon('exit24.png'), 'exit', self)         exitaction.setshortcut('ctrl+q') # set shortcut         # connect action custom function         exitaction.triggered.connect(self.load_yahoo)         # create toolbar , add action         self.toolbar = self.addtoolbar('exit')         self.toolbar.addaction(exitaction)          # setup size , title of main window         self.resize(650, 750)         self.setwindowtitle('browser')          # create web widget , set 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_()) 

Comments

Popular posts from this blog

Detect support for Shoutcast ICY MP3 without navigator.userAgent in Firefox? -

web - SVG not rendering properly in Firefox -

java - JavaFX 2 slider labelFormatter not being used -