python - PyQt: How to load a url from a menu item -


i have main window buttons , plot. added file menu, using qt designer. now, if run app, , can see typical menu bar. problem is, want click on menu bar , perform action - want open internet web page default browser. can me?

this code generated pyuic4 qt designer (i show code file menu):

self.menubar = qtgui.qmenubar(mainwindow) self.menubar.setgeometry(qtcore.qrect(0, 0, 1445, 21)) self.menubar.setobjectname(_fromutf8("menubar")) self.menufile = qtgui.qmenu(self.menubar) self.menufile.setobjectname(_fromutf8("menufile")) mainwindow.setmenubar(self.menubar) self.statusbar = qtgui.qstatusbar(mainwindow) self.statusbar.setobjectname(_fromutf8("statusbar")) mainwindow.setstatusbar(self.statusbar) self.actionfsa_format = qtgui.qaction(mainwindow) self.actionfsa_format.setobjectname(_fromutf8("actionfsa_format")) self.menufile.addaction(self.actionfsa_format) self.menubar.addaction(self.menufile.menuaction()) 

as can see have file menu, , tool-button actionfsa_format action. want click , open external url.

you need connect triggered signal of action handler.

so in __init__ of main window, this:

self.ui.actionfsa_format.triggered.connect(self.openurl) 

and openurl method this:

def openurl(self):     url = qtcore.qurl('http://some.domain.com/path')     if not qtgui.qdesktopservices.openurl(url):         qtgui.qmessagebox.warning(self, 'open url', 'could not open url') 

Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -