def on_downloadRequested(self, downloadItem): #download if downloadItem.isFinished() == False and downloadItem.state() == 0: #print('on_downloadRequested=>%d' % self.mainWindow.index) #filename #the_filename = downloadItem.url().fileName() the_filename = os.path.basename(downloadItem.path()) if len(the_filename) == 0 or "." not in the_filename: cur_time = datetime.datetime.now().strftime('%Y%m%d%H%M%S') the_filename = cur_time + '.' + downloadItem.mimeType().split( '/')[1] if Util.getConfigValue('defaultSavePath'): the_sourceFile = Util.getConfigValue( 'defaultSavePath') + '/' + Util.getRandomFileName( the_filename) else: f = QFileDialog.getSaveFileName(None, "Save File", the_filename, "All files(*.*)") if not f[0]: downloadItem.cancel() return False the_sourceFile = f[0] #the_sourceFile = os.path.join(os.getcwd(), the_filename) # downloadItem.setSavePageFormat(QWebEngineDownloadItem.CompleteHtmlSaveFormat) downloadItem.setPath(the_sourceFile) downloadItem.accept() downloadItem.finished.connect(self.on_downloadFinished) downloadItem.downloadProgress.connect(self.on_downloadProgress)