3

我一直在玩 PyQt4,并意识到它没有达到我的期望。考虑代码

import sys
from PyQt4.QtCore import Qt
from PyQt4.QtGui import QPalette, QGraphicsScene, QGraphicsProxyWidget, QGraphicsView, QPainter
from PyQt4.QtOpenGL import QGLWidget
from PyQt4.QtCore import QObject, pyqtSlot, QUrl
from PyQt4.QtGui import QApplication
from PyQt4.QtWebKit import QWebView, QWebSettings
from batchq.pipelines.interpreters import PythonTerminal
from PyQt4 import QtCore, QtGui, QtWebKit
import PyQt4

class WithConsole(QtWebKit.QWebPage):
    def javaScriptConsoleMessage(self, msg, line, source):
        print '%s line %d: %s' % (source, line, msg)

if __name__ == '__main__':
    app = QApplication(sys.argv)

    webview = QWebView()
    webview.setAttribute(Qt.WA_X11NetWmWindowTypeDesktop)
    webview.setAttribute(Qt.WA_OpaquePaintEvent, True)
    settings=webview.settings()
    settings.setAttribute(QWebSettings.LocalContentCanAccessRemoteUrls, True)
    settings.setAttribute(QWebSettings.LocalContentCanAccessRemoteUrls, True)
    settings.setAttribute(QWebSettings.LocalContentCanAccessFileUrls, True)
    settings.setAttribute(QWebSettings.LocalStorageEnabled, True)
    settings.setAttribute(QWebSettings.AutoLoadImages, True)

    page = WithConsole()
    webview.setPage(page)
    frame = webview.page().mainFrame()
    palette = webview.palette()
    palette.setBrush(QPalette.Base, Qt.transparent)
    webview.page().setPalette(palette)

    scene = QGraphicsScene()
    proxy = QGraphicsProxyWidget()
    proxy.setWidget(webview)
    rect = proxy.boundingRect()
    proxy.setPos(rect.width(), rect.height())
    proxy.show()
    scene.addItem(proxy)

    scene.setSceneRect(scene.itemsBoundingRect())
    view = QGraphicsView()
    view.setScene(scene)
    view.setViewport(QGLWidget())

    view.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform)
    view.setCacheMode(QGraphicsView.CacheBackground)
    view.setViewportUpdateMode(QGraphicsView.BoundingRectViewportUpdate)
    view.show()


    webview.setUrl(QUrl("http://bartaz.github.com/impress.js/#/bored"))
#    webview.setUrl(QUrl("http://gridster.net/"))
    view.show()
    app.exec_()

这实现了一个最小的网络浏览器,它只显示一个启用了 GL 以进行转换等的页面。但是,在几个网页上对其进行测试后,人们立即注意到交互远远落后于其他浏览器,如 Chrome 或 Safari。特别是,在 gridster.net 上,与“网格”的交互并不像预期的那样工作,而对于 impress.js,转换速度非常慢(没有 GL,它们甚至更慢)。最后,这似乎是独立的。PySide 也很慢。Qt 是 4.8.1 版。

我的问题是,是否有可能使 QtWebkit 与 gridster.js 兼容,以及如何提高转换的性能?

4

0 回答 0