How to clone a QGraphicsItem object?



  • Hi,

    Maybe this question is too obvious but I really appreciate any help. What is the best way to make an independent copy of a QGraphicsItem object?

    QGraphicsPathItem *original = new QGraphicsPathItem;
    original->setPath(originalPath);
    
    QGraphicsPathItem *itemCopy = ???
    

    I want to manipulate the object copy without modifying/altering the original item.

    Any hint? :)


  • Qt Champions 2016

    hi
    If you look in source of QGraphicsItem you will see

    private:
    Q_DISABLE_COPY(QGraphicsItem)
    Q_DECLARE_PRIVATE(QGraphicsItem)

    So it is not allowed. ( as far as i know)

    So you can not copy or clone it as such.

    Only option is to create a new item and then copy the data to the new instance.


Log in to reply
 

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