Check the Puzzle example in Qt Demos.
Qt Demos \ Item Views \ Puzzle.

It has similar working to your requirement.