diff options
authorPaul Wicking <>2020-03-06 07:29:12 +0100
committerPaul Wicking <>2020-03-06 08:12:52 +0100
commita2446c0eede445eb40905487b1ba7c689aa8baef (patch)
parentc3ae30085e4047ee7d5a945c36e2055c2de5197d (diff)
Doc: Let SQL Drill Down example show correct use of qgraphicsitem_cast
For qgraphicsitem_cast to work correctly with custom items, one must reimplement the type() function for each custom QGraphicsItem subclass. Do that in the example code. Fixes: QTBUG-7357 Change-Id: Ibf221817908355f0347cddfc46747b6955958f5f Reviewed-by: Andy Shaw <>
2 files changed, 6 insertions, 0 deletions
diff --git a/examples/sql/doc/src/drilldown.qdoc b/examples/sql/doc/src/drilldown.qdoc
index 8beb515a83..a7a9601c26 100644
--- a/examples/sql/doc/src/drilldown.qdoc
+++ b/examples/sql/doc/src/drilldown.qdoc
@@ -437,6 +437,9 @@
\snippet drilldown/imageitem.h 0
+ We declare a \c Type enum value for our custom item and reimplement
+ \l{QGreaphicsItem::}{type()}. This is done so we can safely use
+ qgraphicsitem_cast().
In addition, we implement a public \c id() function to be able to
identify the associated location and a public \c adjust() function
that can be called to ensure that the image item is given the
diff --git a/examples/sql/drilldown/imageitem.h b/examples/sql/drilldown/imageitem.h
index abb9103c7e..324c847b12 100644
--- a/examples/sql/drilldown/imageitem.h
+++ b/examples/sql/drilldown/imageitem.h
@@ -60,8 +60,11 @@ class ImageItem : public QObject, public QGraphicsPixmapItem
+ enum { Type = UserType + 1 };
ImageItem(int id, const QPixmap &pixmap, QGraphicsItem *parent = nullptr);
+ int type() const override { return Type; }
void adjust();
int id() const;