Languages/Python/PyKDE WebKit Tutorial/Part7: Difference between revisions
Neverendingo (talk | contribs) m (Text replace - "</code>" to "</syntaxhighlight>") |
(Mark for archiving) |
||
(One intermediate revision by one other user not shown) | |||
Line 1: | Line 1: | ||
{{Archived}} | |||
{{Warning|This tutorial uses Qt4, PyQt4, and PyKDE4.}} | |||
Finally we want to make our address bar do something. | Finally we want to make our address bar do something. | ||
Latest revision as of 14:04, 31 May 2019
Finally we want to make our address bar do something.
We will use connect a Qt signal from the line edit into a method which will load the address.
Below self.window.show() add this connect line and the following method:
QObject.connect(self.addressBar, SIGNAL("returnPressed()"), self.loadUrl)
def loadUrl(self):
print "Loading " + self.addressBar.text()
self.web.load( QUrl(self.addressBar.text()) )
Qt signals are emitted by objects when interesting things happen. The QLineEdit documentation tells us about the returnPressed() signal. So we connect that from our addressBar line edit into a method we make called loadUrl() In C++ signals are connected to special methods called Slots but in Python we can connect them to any method.
Our loadUrl() method will print out the contents of the address bar onto your terminal, then will load the QWebView with the address. (Remember to include the http:// at the start of the address.)
See the full code.
Our completed web browser, loading a different URL.