As far as I know, that was (is?) not (simply) possible in Krita, and that you do need ways around to do it.
Also, the question is, should your square be vector or raster/pixel-graphics?
You can try to find more information on this in the following topics:
And I suggest using the Krita Scripting School to get more information about it, and maybe you can find more information in the Action Dictionary, a part of the Krita Scripting School.
Maybe there you find a way to code it yourself, and you’ll probably need Qt (functions) for this.
But all these hints are only guesses from a user who knows next to nothing about programming anymore, …