Adding the 'drop' functionality to the field

We can now drag our labels off the toolbar but there is currently no where for them to go! We must turn our attention to reimplementing the event handlers on the receiving object: FieldGraphicsScene.

The event handlers we will need to reimplement are:

  • dragEnterEvent
  • dragMoveEvent
  • dropEvent

The video below demonstrates how to do this.

Task 7b

Use the above video to the ability to detect drop events over the field.


Currently our drag and drop functionality is incomplete - all it does is provide a message in the console to indicate that the drop has been received successfully. We need to build on this to actually add the crops and animals to the field.

The PyQt co-ordinate system

An important part of the drop process is being able to pinpoint precisely where the dragged icon is being dropped. This is achieved by accessing the cursor co-ordinates but there is a problem - PyQt works with three sets of co-ordinates so we need to know which ones to use.

The animation below provides further detail on the PyQt co-ordinate system:

PyQt Co-ordinate Summary

Improving the drop functionality

Now that we have some understanding of the PyQt co-ordinate system we can complete our drag and drop functionality.

The video below demonstrates how to do this.

Task 7c

Use the above video to improve the drop event so that crops and animals can be added to the field.