在浏览器窗口中渲染PyQt小部件

时间:2016-12-13 20:02:10

标签: python python-3.x pyqt chromium pyqt5

我知道我可以在这样的webview中加载PyQt5小部件:

import sys

from PyQt5 import QtCore, QtWebKitWidgets, QtWebKit
from PyQt5.QtWidgets import QApplication, QCalendarWidget


    HTML = """
    <html>
       <head>
          <title>QtWebKit Plug-in Test</title>
       </head>
       <body>
          <h1>Hello, World!</h1>
          <object type="application/x-qt-plugin" classid="MyCalendarWidget" name="calendar" height=300 width=500></object>
          <script>
             calendar.setGridVisible(true);
             calendar.setCurrentPage(1985, 5);
          </script>
       </body>
    </html>
    """


    class MyWebView(QtWebKitWidgets.QWebView):

        def __init__(self, parent=None):

            super(MyWebView, self).__init__(parent)

            self._page = MyWebPage(self)
            self.setPage(self._page)


    class MyWebPage(QtWebKitWidgets.QWebPage):

        def __init__(self, parent=None):

            super(MyWebPage, self).__init__(parent)

            self.settings().setAttribute(QtWebKit.QWebSettings.PluginsEnabled, True)

        def createPlugin(self, classid, url, paramNames, paramValues):

            return MyCalendarWidget(self.view())


    class MyCalendarWidget(QCalendarWidget):

        def __init__(self, parent=None):

            super(MyCalendarWidget, self).__init__(parent)

            # Just to prove that this is being used.
            self.setFirstDayOfWeek(QtCore.Qt.Monday)


    app = QApplication(sys.argv)

    viewer = MyWebView()
    viewer.setHtml(HTML)
    viewer.show()

    app.exec_()

但是,我想知道是否有任何方法可以直接在Chromium Web浏览器中加载PyQt小部件?我猜这是目前不可能的,但我不确定是否有某种方式我没有想到这样做。

0 个答案:

没有答案
相关问题