Alundra
31st March 2014, 12:54
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 :
case ItemPositionChange :
{
// Get the scene.
QGraphicsScene* Scene = scene();
// Check if the scene is invalid.
if( Scene == NULL )
break;
// Cast the scene.
CEditorNodeScene* NodeScene = static_cast< CEditorNodeScene* >( Scene );
// Get the grid step.
const qreal GridStep = static_cast< qreal >( NodeScene->GetGridStep() );
// Snap to grid.
QPointF NewPos = value.toPointF();
NewPos.setX( NewPos.x() - fmod( NewPos.x(), GridStep ) );
NewPos.setY( NewPos.y() - fmod( NewPos.y(), GridStep ) );
return NewPos;
}
Thanks for the help
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 :
case ItemPositionChange :
{
// Get the scene.
QGraphicsScene* Scene = scene();
// Check if the scene is invalid.
if( Scene == NULL )
break;
// Cast the scene.
CEditorNodeScene* NodeScene = static_cast< CEditorNodeScene* >( Scene );
// Get the grid step.
const qreal GridStep = static_cast< qreal >( NodeScene->GetGridStep() );
// Snap to grid.
QPointF NewPos = value.toPointF();
NewPos.setX( NewPos.x() - fmod( NewPos.x(), GridStep ) );
NewPos.setY( NewPos.y() - fmod( NewPos.y(), GridStep ) );
return NewPos;
}
Thanks for the help