If you dont want play with calculating you can reinplement mousePressEvent only for your rectangle