-1
如何將主應用程序內部的打開的文件發送到頁面中QWebEngineView和由JavaScript的FileReader()函數處理它,因爲它是由所述QWebEngineViewpyQt5傳遞一個文件對象QWebEngineView
內部的HTML5文件,輸入開這裏是我的代碼的一部分
# -*- coding: utf-8 -*-
import sys, os
from PyQt5.QtWidgets import (QApplication, QMainWindow)
from PyQt5.QtCore import QUrl
import PyQt5.QtWebEngineWidgets as QtWebEngineWidgets
import interface
class MyWindow(QMainWindow):
def __init__(self, parent=None):
QMainWindow.__init__(self, parent)
self.ui = interface.Ui_MainWindow()
self.ui.setupUi(self)
web_view = QtWebEngineWidgets.QWebEngineView()
self.web_view = web_view
self.ui.verticalLayout_navigateur.addWidget(web_view)
url = self.local_url("src/index.html")
self.web_view.load(url)
f = open('myfile.json', 'r')
#send f to self.web_view and handle it by javascript FileReader() function
def local_url(self, relativePath):
absolutePath = os.path.abspath(relativePath)
url = QUrl.fromLocalFile(absolutePath)
return url
if __name__ == '__main__':
app = QApplication(sys.argv)
window = MyWindow()
window.show()
sys.exit(app.exec_())
感謝
由於Stack Overflow不是代碼編寫服務,因此我正在投票結束此問題。 – IInspectable
我沒有找到如何去做,或者即使有可能做到,任何幫助都是值得的,我不是要求完整的代碼,只是指南 –