SHARE
TWEET

PyQt5 - QWebEngine - download file

furas Jul 21st, 2018 19 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #
  2. # you can test it with local web server
  3. #
  4. # python -m http.server
  5. #
  6. # and it should have url http://localhost:8000
  7. #
  8.  
  9. import sys
  10. import PyQt5.Qt
  11.  
  12.  
  13. def download(item): # QWebEngineDownloadItem
  14.     print('downloading to', item.path())
  15.     item.accept() # accept file and it will download it (without any messages)
  16.  
  17.  
  18. app = PyQt5.Qt.QApplication(sys.argv)
  19. win = PyQt5.Qt.QWebEngineView()
  20.  
  21. # show page title as window title
  22. win.loadFinished.connect(lambda:win.setWindowTitle(win.title()))
  23.  
  24. # assign function which will download clicked files
  25. #profile = PyQt5.Qt.QWebEngineProfile.defaultProfile()
  26. #profile.downloadRequested.connect(download)
  27. win.page().profile().downloadRequested.connect(download)
  28.  
  29. #url = PyQt5.Qt.QUrl('https://google.com')
  30. url = PyQt5.Qt.QUrl('http://localhost:8000')
  31. win.load(url)
  32.  
  33. win.show()
  34.  
  35. app.exec_()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top