mahesht
mahesht

Reputation: 79

Remove QGraphicsPixmapItem if it is added in scene. If not add to scene

How can i remove QGraphicsPixmapItem from the scene if it is already added to scene. If not added then add to scene. I have a attached code below.

QGraphicsPixmapItem *linesadd;
previewScene->removeItem(linesadd); //I want to check here whether linesadd item is added or not.
linesadd = new QGraphicsPixmapItem(pixmap);
previewScene->addItem(linesadd);

Upvotes: 1

Views: 69

Answers (1)

M0rk
M0rk

Reputation: 56

I asume you use QGraphicsScene from your code. If you have a valid pointer to linesadd you have different options.

  1. You can check for QGraphicsScene's itemAt Method
  2. You can iterate over QList returned by QGraphicsScene's items method that fits your needs.

It this is not what you want, please give some more information on your problem.

Best regards

Upvotes: 1

Related Questions