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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
|
//! [0]
scene = QGraphicsScene()
scene.addText("Hello, world!")
view = QGraphicsView(scene)
view.show()
//! [0]
//! [1]
scene = QGraphicsScene()
scene.addRect(QRectF(-10, -10, 20, 20))
view = QGraphicsView(scene)
view.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform)
view.show()
//! [1]
//! [2]
view = QGraphicsView()
view.setBackgroundBrush(QImage(":/images/backgroundtile.png"))
view.setCacheMode(QGraphicsView.CacheBackground)
//! [2]
//! [3]
scene = QGraphicsScene()
scene.addText("GraphicsView rotated clockwise")
view = QGraphicsView(scene)
view.rotate(90) # the text is rendered with a 90 degree clockwise rotation
view.show()
//! [3]
//! [4]
scene = QGraphicsScene()
scene.addItem(...
...
view = QGraphicsView(scene)
view.show()
...
printer = QPrinter(QPrinter.HighResolution)
printer.setPageSize(QPrinter.A4)
painter = QPainter(printer)
# print, fitting the viewport contents into a full page
view.render(painter)
# print the upper half of the viewport into the lower.
# half of the page.
viewport = view.viewport()->rect()
view.render(painter,
QRectF(0, printer.height() / 2,
printer.width(), printer.height() / 2),
viewport.adjusted(0, 0, 0, -viewport.height() / 2))
//! [4]
//! [5]
def mousePressEvent(self, event):
print "There are", items(event->pos()).size(), "items at position", mapToScene(event->pos())
//! [5]
//! [6]
def mousePressEvent(self, event):
if (item = itemAt(event.pos()):
print "You clicked on item", item
else:
print "You didn't click on an item."
//! [6]
//! [7]
scene = QGraphicsScene()
scene.addText("GraphicsView rotated clockwise")
view = QGraphicsView(scene)
view.rotate(90) # the text is rendered with a 90 degree clockwise rotation
view.show()
//! [7]
|