1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4#include <QGraphicsEllipseItem>
5#include <QGraphicsScene>
6#include <QStyleOptionGraphicsItem>
7#include <QtGui>
8
9class CustomScene : public QGraphicsScene
10{
11public:
12 CustomScene()
13 { addItem(item: new QGraphicsEllipseItem(QRect(10, 10, 30, 30))); }
14
15 void drawItems(QPainter *painter, int numItems, QGraphicsItem *items[],
16 const QStyleOptionGraphicsItem options[],
17 QWidget *widget = nullptr) override;
18};
19
20//! [0]
21void CustomScene::drawItems(QPainter *painter, int numItems,
22 QGraphicsItem *items[],
23 const QStyleOptionGraphicsItem options[],
24 QWidget *widget)
25{
26 for (int i = 0; i < numItems; ++i) {
27 // Draw the item
28 painter->save();
29 painter->setTransform(transform: items[i]->sceneTransform(), combine: true);
30 items[i]->paint(painter, option: &options[i], widget);
31 painter->restore();
32 }
33}
34//! [0]
35

source code of qtbase/src/widgets/doc/snippets/graphicssceneadditem/graphicssceneadditemsnippet.cpp