Removing QGraphicsPathItem from scene



  • Hello,
    I am creating a simple QWidget application. I'm stuck at deleting single QGraphicsPathItem object. I start from a QPainterPath object.

    QGraphicsScene *scene;
    QPainterPath foo_path;
    foo_path.moveTo(10,10);
    foo_path.lineTo(20,20);
    QGraphicsPathItem *foo_item = scene->addPath(foo_path);

    QGraphicsScene::removeItem() does not work with QGraphicsPathItem, only with QGraphicsItem.

    Is there a workaround? Thanks.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    What doesn't work for you ?

    QGraphicsPathItem is a subclass of QGraphicsItem.



  • Thank you for your reply.

    I'd like to delete the QGraphicsPathItem using scene->removeItem(foo_item).

    Compiler returns error "no matching function....", since removeItem only works with QGraphicsItem and there is no known conversion from 'QGraphicsPathItem*' to 'QGraphicsItem*'.


  • Lifetime Qt Champion

    This dummy example:

    #include <QApplication>
    #include <QGraphicsScene>
    #include <QGraphicsPathItem>
    #include <QPainterPath>
    
    int main(int argc, char **argv)
    {
        QApplication app(argc, argv);
        QGraphicsScene scene;
        QPainterPath path;
        QGraphicsPathItem *item = scene.addPath(path);
        scene.removeItem(item);
        return 0;
    }
    

    builds without any problem.



  • Forgot the include. Oh god.

    Thank you for your help.


Log in to reply
 

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