Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
src_gui_graphicsview_qgraphicsview.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4//! [0]
6scene.addText("Hello, world!");
7
8QGraphicsView view(&scene);
9view.show();
10//! [0]
11
12
13//! [1]
15scene.addRect(QRectF(-10, -10, 20, 20));
16
17QGraphicsView view(&scene);
18view.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
19view.show();
20//! [1]
21
22
23//! [2]
25view.setBackgroundBrush(QImage(":/images/backgroundtile.png"));
26view.setCacheMode(QGraphicsView::CacheBackground);
27//! [2]
28
29
30//! [4]
32scene.addItem(...
33...
34
35QGraphicsView view(&scene);
36view.show();
37...
38
39QPrinter printer(QPrinter::HighResolution);
40printer.setPageSize(QPrinter::A4);
41QPainter painter(&printer);
42
43// print, fitting the viewport contents into a full page
44view.render(&painter);
45
46// print the upper half of the viewport into the lower.
47// half of the page.
48QRect viewport = view.viewport()->rect();
49view.render(&painter,
50 QRectF(0, printer.height() / 2,
51 printer.width(), printer.height() / 2),
52 viewport.adjusted(0, 0, 0, -viewport.height() / 2));
53
54//! [4]
55
56
57//! [5]
58void CustomView::mousePressEvent(QMouseEvent *event)
59{
60 qDebug() << "There are" << items(event->pos()).size()
61 << "items at position" << mapToScene(event->pos());
62}
63//! [5]
64
65
66//! [6]
67void CustomView::mousePressEvent(QMouseEvent *event)
68{
69 if (QGraphicsItem *item = itemAt(event->pos())) {
70 qDebug() << "You clicked on item" << item;
71 } else {
72 qDebug("You didn't click on an item.");
73 }
74}
75//! [6]
76
77
78//! [7]
79QGraphicsScene scene;
80scene.addText("GraphicsView rotated clockwise");
81
82QGraphicsView view(&scene);
83view.rotate(90); // the text is rendered with a 90 degree clockwise rotation
84view.show();
85//! [7]
QGraphicsScene scene
[0]
QQuickView * view
[0]