Python - PyQt4 (Webkit) How to set value of input(

2019-08-28 05:19发布

I'm trying to upload a file using QWebPage module of (WebKIt) like this.

<form action="#">
Select a file: <input type="file" id="photos_upload_input" multiplie="">
<input type="submit">
</form>

I try it:

class WebPage(QWebPage):
    def __init__(self, parent = None):
        QWebPage.__init__(self)
        self.overrideUpload = None

    def extension(self, extension, option, output):
        '''
        The behavior of this function is determined by extension . 
        The option and output values are typically casted to the corresponding types (for example, 
        ChooseMultipleFilesExtensionOption and ChooseMultipleFilesExtensionReturn for ChooseMultipleFilesExtension )
        '''
        if self.overrideUpload is None:
            return super(WebPage, self).extension(self, extension, option, output)
        result = self.overrideUpload
        ....?

1条回答
爷、活的狠高调
2楼-- · 2019-08-28 06:18

Solution:

...
def extension(self, extension, option, output):
    if (extension == self.ChooseMultipleFilesExtension):
        if self.overrideUpload is None:
            return super(WebPage, self).extension(self, extension, option, output)
        file_upl = self.overrideUpload
        self.overrideUpload = None
        output.fileNames = QStringList([file_upl])
        return True
    return False
...
查看更多
登录 后发表回答