Hi all,
I have implemented the snap to grid on the QGraphicsItem but sometimes one item move and other doesn't when multi selected.
Here the code I use to snap to grid inside itemChange of QGraphicsItem :
Qt Code:
  1. case ItemPositionChange :
  2. {
  3. // Get the scene.
  4. QGraphicsScene* Scene = scene();
  5.  
  6. // Check if the scene is invalid.
  7. if( Scene == NULL )
  8. break;
  9.  
  10. // Cast the scene.
  11. CEditorNodeScene* NodeScene = static_cast< CEditorNodeScene* >( Scene );
  12.  
  13. // Get the grid step.
  14. const qreal GridStep = static_cast< qreal >( NodeScene->GetGridStep() );
  15.  
  16. // Snap to grid.
  17. QPointF NewPos = value.toPointF();
  18. NewPos.setX( NewPos.x() - fmod( NewPos.x(), GridStep ) );
  19. NewPos.setY( NewPos.y() - fmod( NewPos.y(), GridStep ) );
  20. return NewPos;
  21. }
To copy to clipboard, switch view to plain text mode 
Thanks for the help