Difference between revisions of "Languages/Python/PyKDE WebKit Tutorial/Part7"

Jump to: navigation, search
(New page: 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 ...)
 
m (Text replace - "</code>" to "</syntaxhighlight>")
(2 intermediate revisions by 2 users not shown)
Line 5: Line 5:
 
Below ''self.window.show()'' add this connect line and the following method:
 
Below ''self.window.show()'' add this connect line and the following method:
  
<code python>
+
<syntaxhighlight lang="python">
 
         QObject.connect(self.addressBar, SIGNAL("returnPressed()"), self.loadUrl)
 
         QObject.connect(self.addressBar, SIGNAL("returnPressed()"), self.loadUrl)
  
Line 11: Line 11:
 
         print "Loading " + self.addressBar.text()
 
         print "Loading " + self.addressBar.text()
 
         self.web.load( QUrl(self.addressBar.text()) )
 
         self.web.load( QUrl(self.addressBar.text()) )
</code>
+
</syntaxhighlight>
  
 
Qt signals are emitted by objects when interesting things happen.  The [http://doc.trolltech.com/4.4/qlineedit.html#returnPressed 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.
 
Qt signals are emitted by objects when interesting things happen.  The [http://doc.trolltech.com/4.4/qlineedit.html#returnPressed 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.
Line 24: Line 24:
  
 
[[Development/Languages/Python/PyKDE_WebKit_Tutorial/Part6|« Back to Part 6]] | [[Development/Languages/Python/PyKDE_WebKit_Tutorial/Conslusion|On to conclusion »]]
 
[[Development/Languages/Python/PyKDE_WebKit_Tutorial/Part6|« Back to Part 6]] | [[Development/Languages/Python/PyKDE_WebKit_Tutorial/Conslusion|On to conclusion »]]
 +
 +
[[Category:Python]]

Revision as of 20:50, 29 June 2011

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.

Pykde-tutorial-4.png

« Back to Part 6 | On to conclusion »