1 | //! [0]
|
---|
2 | QGraphicsScene scene;
|
---|
3 | QGraphicsRectItem *rect = scene.addRect(QRectF(0, 0, 100, 100));
|
---|
4 |
|
---|
5 | QGraphicsItem *item = scene.itemAt(50, 50);
|
---|
6 | // item == rect
|
---|
7 | //! [0]
|
---|
8 |
|
---|
9 |
|
---|
10 | //! [1]
|
---|
11 | QGraphicsScene scene;
|
---|
12 | myPopulateScene(&scene);
|
---|
13 |
|
---|
14 | QGraphicsView view(&scene);
|
---|
15 | view.show();
|
---|
16 | //! [1]
|
---|
17 |
|
---|
18 |
|
---|
19 | //! [2]
|
---|
20 | class View : public QGraphicsView
|
---|
21 | {
|
---|
22 | Q_OBJECT
|
---|
23 | ...
|
---|
24 | public slots:
|
---|
25 | void zoomIn() { scale(1.2, 1.2); }
|
---|
26 | void zoomOut() { scale(1 / 1.2, 1 / 1.2); }
|
---|
27 | void rotateLeft() { rotate(-10); }
|
---|
28 | void rotateRight() { rotate(10); }
|
---|
29 | ...
|
---|
30 | };
|
---|
31 | //! [2]
|
---|
32 |
|
---|
33 |
|
---|
34 | //! [3]
|
---|
35 | QGraphicsScene scene;
|
---|
36 | scene.addRect(QRectF(0, 0, 100, 200), QPen(Qt::black), QBrush(Qt::green));
|
---|
37 |
|
---|
38 | QPrinter printer;
|
---|
39 | if (QPrintDialog(&printer).exec() == QDialog::Accepted) {
|
---|
40 | QPainter painter(&printer);
|
---|
41 | painter.setRenderHint(QPainter::Antialiasing);
|
---|
42 | scene.render(&painter);
|
---|
43 | }
|
---|
44 | //! [3]
|
---|
45 |
|
---|
46 |
|
---|
47 | //! [4]
|
---|
48 | QGraphicsScene scene;
|
---|
49 | scene.addRect(QRectF(0, 0, 100, 200), QPen(Qt::black), QBrush(Qt::green));
|
---|
50 |
|
---|
51 | QPixmap pixmap;
|
---|
52 | QPainter painter(&pixmap);
|
---|
53 | painter.setRenderHint(QPainter::Antialiasing);
|
---|
54 | scene.render(&painter);
|
---|
55 | painter.end();
|
---|
56 |
|
---|
57 | pixmap.save("scene.png");
|
---|
58 | //! [4]
|
---|
59 |
|
---|
60 |
|
---|
61 | //! [5]
|
---|
62 | void CustomItem::mousePressEvent(QGraphicsSceneMouseEvent *event)
|
---|
63 | {
|
---|
64 | QMimeData *data = new QMimeData;
|
---|
65 | data->setColor(Qt::green);
|
---|
66 |
|
---|
67 | QDrag *drag = new QDrag(event->widget());
|
---|
68 | drag->setMimeData(data);
|
---|
69 | drag->start();
|
---|
70 | }
|
---|
71 | //! [5]
|
---|
72 |
|
---|
73 |
|
---|
74 | //! [6]
|
---|
75 | QGraphicsView view(&scene);
|
---|
76 | view.setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
|
---|
77 | //! [6]
|
---|