PDA

View Full Version : Remove a QGraphicsItem from a QList and find out the index of the item in the list



rakefet
13th March 2014, 14:55
Hi,

I have a code that generates two QList:
QList<QGraphicsItems *>
QList<QPointF>

When a user clicks on the middle mouse on a scene, a new item is added to the first list and its position is added to the second list.

I want to be able to remove an item from a scene if the user clicks on the middle mouse on the item on the scene. something like:


if (e->buttons().testFlag(Qt::MidButton))
{
QGraphicsItem *item;
item = itemAt(e->scenePos());
if (item)
{
this->Scene->removeItem(item);
/* remove the location of the item from QList<QPointF> */
}
I was thinking that if I'll have a way to know the location of the item in the QList<QGraphicsItems *>, I'll be able to remove its position from QList<QPointF>.

How can I do this?

Thank you for any solutions.

anda_skoa
13th March 2014, 17:32
QList::indexOf()

Cheers,
_

rakefet
13th March 2014, 19:11
Thank you. it works!