blob: 239309e65e71bdd42ea5f96099db28b0150529ec (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
from PySide.QtGui import *
from PySide.QWebKit import QWebPage
from PySide.QWebKit import QWebFrame
//! [0]
class Thumbnailer(QObject):
page = QWebPage()
//! [1]
def __init__(self, url):
page.mainFrame().load(url)
connect(page, SIGNAL("loadFinished(bool)"),
self, SLOT("render()"))
//! [1]
//! [2]
def render(self):
page.setViewportSize(page.mainFrame().contentsSize())
image = QImage(page.viewportSize(), QImage.Format_ARGB32)
painter = QPainter(image)
page.mainFrame().render(painter)
painter.end()
thumbnail = image.scaled(400, 400)
thumbnail.save("thumbnail.png")
self.finished()
//! [2]
//! [0]
def main():
app = QApplication([])
thumbnail = Thumbnailer(QUrl("http://qtsoftware.com"))
QObject.connect(thumbnail, SIGNAL("finished()"),
app, SLOT("quit()"))
return app.exec_()
#include "main.moc"
|