Results 1 to 3 of 3

Thread: Remove a QGraphicsItem from a QList and find out the index of the item in the list

  1. #1
    Join Date
    Feb 2014
    Posts
    26
    Qt products
    Qt5
    Platforms
    Windows

    Default Remove a QGraphicsItem from a QList and find out the index of the item in the list

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Remove a QGraphicsItem from a QList and find out the index of the item in the lis

    QList::indexOf()

    Cheers,
    _

  3. #3
    Join Date
    Feb 2014
    Posts
    26
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Remove a QGraphicsItem from a QList and find out the index of the item in the lis

    Thank you. it works!

Similar Threads

  1. Sort Qlist and return index
    By enricong in forum Qt Programming
    Replies: 3
    Last Post: 20th July 2012, 14:19
  2. Replies: 1
    Last Post: 23rd April 2011, 17:33
  3. Qt Assistant Only one index item built from keyword list in qhp file
    By joekemp in forum Qt Tools
    Replies: 1
    Last Post: 10th March 2011, 17:29
  4. QFileSystemModel::remove not removing index from model
    By revorgm in forum Qt Programming
    Replies: 1
    Last Post: 27th February 2011, 09:24
  5. QList index out of range problem
    By MarkoSan in forum Qt Programming
    Replies: 2
    Last Post: 26th March 2008, 08:40

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.