QGraphicsScene - clone selected item by Alt+Move
Hi!
I want clone selected item at QGraphicsScene if user start moving item with pressed Alt.
I wrote this code:
Code:
if(mouseEvent->modifiers() == Qt::AltModifier)
{
QList<QGraphicsItem *> itList = this->selectedItems();
if(itList.size()==1)
{
DiagramElement *de = (DiagramElement*)itList[0];
DiagramElement *declone = de->clone();
de->setSelected(false);
declone->setPos(mouseEvent->scenePos());
this->addItem(declone);
declone->setSelected(true);
}
}
This code is in class-child of QGraphicsScene. DiagramElement is child of QGraphicsItem.
After cloning old and new items are selected and moving together.
Old item is to stay in place and not be selected.
Re: QGraphicsScene - clone selected item by Alt+Move
Hi,
first just a note: avoid old c style casts. As to your problem (without testing), try to call QGraphicsScene::clearSelection() and then select the cloned item.
Re: QGraphicsScene - clone selected item by Alt+Move
Thanks! I solved this problem wits methogs grabMouse() and ungrabMouse().