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
graphicssceneadditemsnippet.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#include <QGraphicsEllipseItem>
5#include <QGraphicsScene>
6#include <QStyleOptionGraphicsItem>
7#include <QtGui>
8
10{
11public:
13 { addItem(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(items[i]->sceneTransform(), true);
30 items[i]->paint(painter, &options[i], widget);
31 painter->restore();
32 }
33}
34//! [0]
void drawItems(QPainter *painter, int numItems, QGraphicsItem *items[], const QStyleOptionGraphicsItem options[], QWidget *widget=nullptr) override
[0]