[PyKDE] Re: KHTMLPart and link navigation

David Boddie david at boddie.org.uk
Mon Jul 7 20:15:01 BST 2003


On Sun, 6 Jul 2003 18:17:11, Jim Bublitz <jbublitz at nwinternet.com> wrote:

> 2. Check the KDE classref docs (you can get them at kde.org if
> you don't already have them) for KHTMLPart. My first guess would
> be that clicking a link will cause the 'urlSelected' signal to
> be emitted (easy to test), and you can connect a slot to that a
> probably call 'openURL' to load the link (also easy to test).

Or you can just subclass KHTMLPart and create a method to handle clicks.
Something along these lines:

class HTMLPart(KHTMLPart):

    def __init__(self, parent):
    
        KHTMLPart.__init__(self, parent)

        # Other initialisation code goes here.

    def urlSelected(self, url, button, state, target, args):
    
        if button == QMouseEvent.LeftButton:
        
            # Construct a new URL.
            new_url = self.make_url(url)
            
            # Inform the parent object of the new URL so that it can
            # add it to the history trail.
            self.parent.add_next_url(new_url.url(0, 0))
            
            # Open the URL.
            self.openURL(new_url)
    
    def make_url(self, url):
    
        # Is the URL absolute or relative?
        if KURL.isRelativeURL(url):
        
            # A relative URL
            
            # Join the current URL and the new URL.
            new_url = KURL(KURL(self.url()), url)
        
        else:
        
            # Create a KURL object to use to open the new URL.
            new_url = KURL(url)
        
        return new_url

    # Other methods go here.




More information about the PyQt mailing list