Important: Please read the Qt Code of Conduct -

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;
    QGraphicsPathItem *itemCopy = ???

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

    Any hint? :)

  • Lifetime Qt Champion

    If you look in source of QGraphicsItem you will see


    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