我一直在玩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兼容,以及如何改善转换的性能?