[PyQt] Transferring security context to newly created QWebView windows

me at alandmoore.com me at alandmoore.com
Wed Jun 13 20:14:07 BST 2012


Below is some code that illustrates a problem I've been having for several
months now.  I've got a widget based on the QWebView that needs to be able
to open pop-up windows (e.g., links with target="_blank" or javascript
window.open() calls) in a password-protected context.

I can get the windows created just fine by overriding createWindow, but
the security credentials are not transferred over.  In "real" web browsers
(firefox/chrome/opera/rekonq/etc), once authenticated any subsequent
windows in the security context work fine.  How do I recreate this behavior
in a QWebView?

See example code:

######################
# Begin Code Example #
######################

from PyQt4.QtCore import *
from PyQt4.QtGui import *
from PyQt4.QtWebKit import *
import sys

class mybrowser(QWebView):

    def __init__(self, parent=None):
        super(mybrowser, self).__init__(parent)
        url = QUrl ("http://www.alandmoore.com/wwwtest")
        url.setUserName("test")
        url.setPassword("test123")
        self.load(url)

    def createWindow(self, type):
        self.w = mybrowser()
        self.w.show()
        return self.w

if __name__ == '__main__':
    app = QApplication(sys.argv)
    w = mybrowser()
    w.show()
    app.exec_()

####################
# End Code Example #
####################



More information about the PyQt mailing list