qtsoul
3rd December 2011, 15:43
Hi!
I want clone selected item at QGraphicsScene if user start moving item with pressed Alt.
I wrote this 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);
}
QGraphicsScene::mouseMoveEvent(mouseEvent);
}
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.
I want clone selected item at QGraphicsScene if user start moving item with pressed Alt.
I wrote this 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);
}
QGraphicsScene::mouseMoveEvent(mouseEvent);
}
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.