Results 1 to 4 of 4

Thread: QGraphicsScene/QGraphicsView is selecting only one item

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2011
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QGraphicsScene/QGraphicsView is selecting only one item

    Hello!

    Situation:
    I have a QGraphicsScene, QGraphicsView and several QGraphicsEllipseItems on it;
    I enabled selecting and moving for the ellipse items;

    What happens:
    When I double click on an item, it is being selected - that's ok.
    When I double click on another item then, it is not being selected, but the first still has its selection.

    I overrode the doubleMouseClick method of QGraphicsView and I made it clear all the items from slection, before calling its parent method. It looks like this
    Qt Code:
    1. void MyGraphicsView::mouseDoubleClickEvent(QMouseEvent *event){
    2. QList<QGraphicsItem*> list = this->scene()->items();
    3. foreach(QGraphicsItem* item, list){
    4. item->setSelected(false);
    5. qDebug()<<"selection: "<<item->isSelected();
    6. }
    7. QGraphicsView::mouseDoubleClickEvent(event);
    8. foreach(QGraphicsItem* item, list){
    9. qDebug()<<"selection: "<<item->isSelected();
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 

    It behaves now like this:
    before click: one item has isSelected()=true;
    after clicking, before calling parent method: all items have isSelected()=false;
    after calling parent method: the first item (not the one I clicked now) has isSelected()=true;

    So, as a result, the first clicked item "steals" the selection from the others.
    By the way, I checked the result of itemAt(mouse position) function, and it returns the proper item.

    I'm very confused, help would be really appreciated.
    Last edited by jjkrol; 28th May 2011 at 19:17.

Similar Threads

  1. QGraphicsView, QGraphicsScene item coordinates in scene
    By harakiri in forum Qt Programming
    Replies: 2
    Last Post: 5th December 2010, 10:02
  2. Selecting an item from QListWidget
    By chandru@080 in forum Qt Programming
    Replies: 1
    Last Post: 18th November 2010, 06:30
  3. Replies: 0
    Last Post: 12th April 2010, 12:22
  4. selecting a specific QtreeList item
    By MrGarbage in forum Qt Programming
    Replies: 1
    Last Post: 9th October 2007, 13:45
  5. QListWidget and selecting an item
    By invictus in forum Newbie
    Replies: 4
    Last Post: 19th June 2007, 11:59

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
  •  
Qt is a trademark of The Qt Company.