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
void MyGraphicsView
::mouseDoubleClickEvent(QMouseEvent *event
){ QList<QGraphicsItem*> list = this->scene()->items();
item->setSelected(false);
qDebug()<<"selection: "<<item->isSelected();
}
qDebug()<<"selection: "<<item->isSelected();
}
}
void MyGraphicsView::mouseDoubleClickEvent(QMouseEvent *event){
QList<QGraphicsItem*> list = this->scene()->items();
foreach(QGraphicsItem* item, list){
item->setSelected(false);
qDebug()<<"selection: "<<item->isSelected();
}
QGraphicsView::mouseDoubleClickEvent(event);
foreach(QGraphicsItem* item, list){
qDebug()<<"selection: "<<item->isSelected();
}
}
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.
Bookmarks