I make my own class from QWidget
with redefine of paintEvent()
, mousePressEvent()
, mouseReleaseEvent()
and mouseMoveEvent()
. All that methods for move widgets over other widget (yellow).
When i create my widgets in a layout, it looks like this:
But when I move black widget to the bottom and red to the top like this:
and resize window, all widgets refresh to their align positions:
But i want, when i move one widget higher then another, the widgets should align in layout in new places, like this:
Which function i should redefine to do it?
P.S.
There is a piece of code, that can move widgets positions inside layout (change their indexes), but i don't know how find out their (x,y) position to calculate new indexes in layout. I think, that i can do it in resizeEvent()
.
But it when it event was emitted, positions already changed to old. (like before moveing on 1 picture), and i need positions after moveing (like on secon picture). How can i get position of widget before it will be aligned?
or How can i change order of widget in layout by drag and drop with the mouse?
resizeEvent()
i got new position yet" especially after another peculiar piece of text: "but i don't know how know their positions". I will format your images but the rest is up to you. – rbaleksandarQGraphicsScene
withQGraphicsProxyWidget
where you can set thez value
which determines which item overlaps which. – rbaleksandarresize event
you will have both the new and the old values at your disposal. As mentioned in my previous comment what you are doing seems a lot like a job forQGraphicsScene
. If you still don't want to use it you have to enable each of your widgets to be draggable (see thedragEnterEvent
and relative functions part ofQWidget
) as well as being able to accept drops (seeacceptDrops
anddropEvent
- again part ofQWidget
). – rbaleksandar