[PyKDE] KHTMLPart and link navigation

Timothy Bogdala timothy at solipsistic.net
Sun Jul 6 22:16:01 BST 2003


Hello,

I'm pretty new to PyKDE, and KDE programming. I set up a basic program that 
has a KHTMLPart. My problem is that once it loads a url, if you click any 
links on the page, nothing happens. How can I get it so that it navigates 
clicked links?

TIA! Here's a sampling of my code. Once the return is pressed inside the url 
text box, it loads /., but none of the links actually do anything. How can I 
fix this?

from qt import *
from khtml import *
from kdecore import *
from kdeui import *
import sys


class MainWindow(KMainWindow):
	def __init__(self,name):
		KMainWindow.__init__(self)
		self.setCaption("Testing")

		vbox = QVBox(self)

		self.location = QLineEdit(vbox)
		self.location.setText("http://www.slashdot.org")

		self.browser = KHTMLPart(vbox) # Need to be memeber
		self.browser.setJScriptEnabled(True)
		self.browser.setJavaEnabled(True)
		self.browser.setMetaRefreshEnabled(True)
		self.browser.setPluginsEnabled(True)

		self.browser.openURL(KURL("http://www.slashdot.org"))

		self.connect(self.location,SIGNAL("returnPressed()"),self.changeLocation)
		self.setCentralWidget(vbox )

	def changeLocation(self):
		self.browser.openURL(KURL(self.location.text()))


app = KApplication(sys.argv, "Test")
win = MainWindow("Test")
win.resize(800,600)
app.setMainWidget(win)
win.show()
app.exec_loop()




More information about the PyQt mailing list