Python - PyQt4(Webkit)如何设置输入值(type =“file”multiple =“”)?

时间:2014-03-21 12:31:58

标签: python webkit qt4 pyqt4 pyside

我尝试使用({3}}的(WebKIt)QWebPage模块上传文件。

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

我试试看:

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 个答案:

答案 0 :(得分:2)

解决方案:

...
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
...