I'm using a custom QGraphicsScene in which you can click to create a custom QGraphicsItem, then drag (with the mouse still held down) to resize it. To do this, overrode QGraphicsItem::mousePressEvent and mouseMoveEvent, and it worked fine. It was something like this:

Qt Code:
  1. MyScene::mousePressEvent(QGraphicsSceneMouseEvent *event)
  2. {
  3. itemBeingCreated = new MyItem(event->pos()) // "itemBeingCreated" is declared in myscene.h
  4. }
  5.  
  6. MyScene::mouseMoveEvent(QGraphicsMouseEvent *event)
  7. {
  8. itemBeingCreated->resize(/* etc */) // basically how far you drag it from its origin, that's how big it'll be
  9. }
To copy to clipboard, switch view to plain text mode 

Now I am trying to add undo/redo capability with QUndoStack and QUndoCommand. So now my mousePressEvent does this

Qt Code:
  1. MyScene::mousePressEvent(QGraphicsSceneMouseEvent *event)
  2. {
  3. undoStack->push(new AddNewItem(/* etc */)); // "AddNewItem" is a QUndoCommand
  4. }
To copy to clipboard, switch view to plain text mode 

But I don't understand how I can access the item created by "AddNewItem" in order to resize it in MyScene:nMouseMove. Should I just implement a "QGraphicsItem *AddNewItem::getCreatedItem()", or will that "break" the command pattern and lead to problems?