DiagramScene Eaxmple, supplied with PyQt, implements most of the necessary functions. It has a fixed background grid, you can create a rectangle object, but it does not change and does not snap to the grid.
This article has an overflow of https://stackoverflow.com/a/3129269/169268/ ... there are recommendations for resizing graphic objects with the mouse. This is for C ++ Qt, but the technique should be easily replicated to PyQt.
To snap to the grid, I do not think that there is built-in functionality. You probably need to override the itemChange function (GraphicsItemChange change, const QVariant & value). Pseudocode:
if (object not possitioned exactly on the grid): (possition the item on the grid)
Returning the item will cause itemChange to be called again, but this is normal because the item will be correctly entered and will not be moved again, so you wonโt get stuck in an infinite loop.
Simon hibbs
source share