Found the solution to the problem.
{
super.mouseMoveEvent(event);
if (movingBlock != null)
{
if(movingBlock.pos().x() <= 0.0)
{
movingBlock.setPos(0.0, movingBlock.y());
}
if(movingBlock.pos().x() >= this.sceneRect().width())
{
movingBlock.setPos(this.sceneRect().width(), movingBlock.y());
}
if(movingBlock.pos().y() <= 0)
{
movingBlock.setPos(movingBlock.x(), 0.0);
}
if(movingBlock.pos().y() >= this.sceneRect().height())
{
movingBlock.setPos(movingBlock.x(), this.sceneRect().height());
}
}
}
public void mouseMoveEvent(QGraphicsSceneMouseEvent event)
{
super.mouseMoveEvent(event);
if (movingBlock != null)
{
if(movingBlock.pos().x() <= 0.0)
{
movingBlock.setPos(0.0, movingBlock.y());
}
if(movingBlock.pos().x() >= this.sceneRect().width())
{
movingBlock.setPos(this.sceneRect().width(), movingBlock.y());
}
if(movingBlock.pos().y() <= 0)
{
movingBlock.setPos(movingBlock.x(), 0.0);
}
if(movingBlock.pos().y() >= this.sceneRect().height())
{
movingBlock.setPos(movingBlock.x(), this.sceneRect().height());
}
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks