2011-09-02 33 views
3

我正在使用PySide和QWebView在Windows上提供WebKit版本的webapp。如何使用QWebView和PySide加倍緩衝WebKit頁面?

簡單易於安裝在只有Internet Explorer存在的複雜工作Windows環境中。

更多使用過它QWebKit很簡單:

#!/usr/bin/env python 
#-*- coding:utf-8 -*- 

#  hellowebkit.py 


#  Copyright 2009 Piotr Maliński, [email protected] 
#  
#  <Under GPL licence> 

import sys 
from PySide.QtCore import * 
from PySide.QtGui import * 
from PySide.QtWebKit import * 

app = QApplication(sys.argv) 

web = QWebView() 
web.load(QUrl("http://myapp.example.com")) 
web.show() 

sys.exit(app.exec_()) 

我想啓用雙緩衝,因此沒有圖紙,直到下一個頁面完全加載。

你知道我該怎麼做嗎? 我猜可能使用web.loadFinished()信號?

乾杯,

Natim

回答

3

您可以使用QStackedWidgetQSignalMapper做到這一點:

import sys 
from PySide.QtCore import * 
from PySide.QtGui import * 
from PySide.QtWebKit import * 

app = QApplication(sys.argv) 

# Create a stack with 2 webviews 
stack = QStackedWidget() 
mapper = QSignalMapper(stack) 
mapper.mapped[int].connect(stack.setCurrentIndex) 
for i in range(2): 
    web = QWebView(stack) 
    stack.addWidget(web) 
    # When a webview finishes loading, switch to it 
    web.loadFinished[bool].connect(mapper.map) 
    mapper.setMapping(web, i) 

# load the page in the non visible webview 
stack.widget(1).load(QUrl("http://myapp.example.com")) 
stack.show() 

sys.exit(app.exec_())