1
votes

I'm currently building a program in QT in which I have several custom widgets in a frame, and upon a button press more will enter the frame. I've implemented my own functionality to drag and move them around the frame, and that all works fine, but here's the problem: When I already have some of these widgets on the screen that have moved from their initial location and I go to add another widget to the layout, the entire layout resets the locations of every widget beneath it.

I've been using .move(x,y) to move them around, and .addWidget(my widget) as the way to add the widgets to the layout.

Is there any way to prevent this, or some sort of work around? Or if nothing else, any other way to add them to the frame in which they wont automatically move around when a new one is added?

1
Moving widgets manually doesn't go well with layouting them at the same time.Frank Osterfeld
What would be the appropriate way to insert my widgets into a frame whenever I want (by code), and still retain the ability to move them around at will?Yattabyte

1 Answers

0
votes

I solved my problem to some degree, but it is a bit of a work around. Since when new widgets were added to the layout the layout would repaint them all so that they were spaced apart/aligned with the parameters it was set with, I attempted to compensate for this function by saving to each widget its x,y coordinates and move them back immediately once a new widget was added to the layout.

Initially the effort was in vain since SOMEHOW the layout detected this or something, and immediately moved them back. However, this is how I solved it - I just used a stackedWidget. It would still try to automatically orientate each with some spacing when a new widget was added, but my little for loop to re-move every sub widget back (which I haven't changed whatsoever) now works.