[PyQt] QWebView.page() and setPage()

Detlev Offenbach detlev at die-offenbachs.de
Tue Feb 5 17:36:04 GMT 2013



On Sunday 03 February 2013, 18:13:00 Jiangcheng Bao wrote:
> I am trying to store a current page held by QWebView away, then after
> loading and processing a different page, restore the previous page,
> without having to actually request it again, but it seems that by
> doing the following, the application lost my original page, and still
> gives me back the new one. Maybe because it is just a reference to the
> page itself. Is there anyway I can actually store that page and reuse
> it, just like a regular browser would cache the page and load it
> relatively quickly when you revisit it?
> 
> Thanks
> J
> 
> import sys
> from time import sleep
> 
> from PyQt4.QtGui import QApplication
> from PyQt4.QtCore import QUrl
> from PyQt4.QtWebKit import QWebView
> 
> class Browser(QWebView):
> 
>     def __init__(self):
>         QWebView.__init__(self)
>         self.loadFinished.connect(self.load_finished)
> 
>     def load_finished(self, ok):
>         print('page title: ' + self.title())
> 
> if __name__ == '__main__':
>     app = QApplication(sys.argv)
>     browser = Browser()
> 
>     browser.load(QUrl('http://www.google.com'))
> 
>     # store this result away
>     google_page = browser.page()

Did you try:
    google_page = QWebPage(browser.page())

>     print('current page: ' + browser.title())
>     # now load a different page
> 
>     browser.load(QUrl('http://www.yahoo.com'))
>     print('some other page: ' + browser.title())
> 
>     #if browser.page():
>     #browser.page().setView(None)
> 
>     # lets put back my old page
>     browser.setPage(google_page)
>     print('my original page: ' + browser.title())
> 
>     exit(app.exec_())
> _______________________________________________
> PyQt mailing list    PyQt at riverbankcomputing.com
> http://www.riverbankcomputing.com/mailman/listinfo/pyqt

Detlev
-- 
Detlev Offenbach
detlev at die-offenbachs.de
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20130205/2cabf930/attachment.html>


More information about the PyQt mailing list