Get correct QGraphicsItem

  • I have a custom class derived from QGraphicsItem. In that class I have private data member which is QGraphicsSvgItem. In my custom class constructor I am creating a QGraphicsSvgItem and its parent as my custom class. Below what I did.

    @class CustomItem : public QGraphicsItem
    QGraphicsSvgItem *svgItem;

    svgItem = new QGraphicsSvgItem(fileName,this);

    Besides this I have another class(CustomItem2). With this class I am filtering CustomItem events.(I set all my CustomItems parent as CustomItem2)
    When CustomItem2 filters an event which belongs to CustomItem i can't get information about CustomItem because the watched object returns as QGraphicsSvgItem.
    But i want the object return as CustomItem.
    How can I solve this?

  • You can solve this by making CustomItem a QGraphicsSvgItem:

    @ class CustomItem : public QGraphicsSvgItem

    CustomItem::CustomItem(QGraphicsItem *parent) :
    QGraphicsSvgItem(fileName, parent)


Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.