Copy - Paste QGraphicsItem on QGraphicsScene
Hi All,
I am developing a graphics editor where I draw a polygon on the QGraphicsScene from a polygon class derived from QGraphicsItem. I use the painter->drawLine() to connect all the points to draw the polygon in the paint().
The co-ordinates are saved in my struct which has other properties in addition to the points. Now I need to copy and paste the polygon on the scene. I am picking up bits and pieces of QClipboard, QMimeData and QVariant, but I am yet to figure how best I can utilized these classes for my purpose. Am I heading in the right direction? Some pointers will be really helpful.
Thanks in advance.
Re: Copy - Paste QGraphicsItem on QGraphicsScene
Ok guys, I managed to figure out how this could be done.
Implemented the keyPressEvent and handled as below
Code:
if (pKeyEvent->key() == Qt::Key_C && pKeyEvent->modifiers() & Qt::ControlModifier)
{
listCopiedItems = this->selectedItems();
}
if (pKeyEvent->key() == Qt::Key_V && pKeyEvent->modifiers() & Qt::ControlModifier)
{
for(int i=0; i< listCopiedItems.count(); i++)
{
//the same implementation I did to construct the original item during creation after taking the co-ordinates from the original and did a setPos of the item to paste it with a small offset from the original item
}
}
Thanks everyone who tried to think about this.
cheers!
Re: Copy - Paste QGraphicsItem on QGraphicsScene
That works, but I believe using QKeySequence would be a little better, e.g., QKeySequence::Cut, QKeySequence::Copy, and QKeySequence::Paste.