I ran in to a problem where I was doing property animations on widgets but they animation positions wo开发者_如何学编程uld seem to get overwritten on the next layout pass. The widgets would seem to jump position right at the beginning of animation, making it look bad. As a result I thought maybe if I wrote my own layout code I could have more control over things.
What is the easiest way to write a custom layout in QT? I tried following the steps in the "Manual Layout" section of the documentation: http://doc.qt.nokia.com/latest/layout.html#manual-layout However I seem to be hitting a crash when I try calling setGeometry on the child widgets. Also, the docs seem to conflict with the "Manual Layout" saying to call setGeometry from within resizeEvent and the resizeEvent doc saying not to do that.
I suppose I could just write a real layout class. Doesn't look like too much code. But I'm wondering what the easiest/simplest way to get custom layout is.
I think this might work.
Start with widget A positioned entirely outside of the parent widget. Do not add that widget to the layout. A's geometry may well share an edge with the parent.
Create a dummy widget D that forwards A's sizeHint() but does nothing else. Put it into the layout.
Animate widget A toward the geometry of widget D.
Swap the widgets in the layout (remove widget D, add widget A).
If widgets A and D are of your own making, then you should be using the PIMPL idiom. If your widget has no child widgets, swapping the widgets would be trivial -- swap the pimpl pointers. The widgets themselves don't have to be swapped then. DO NOT derive your PIMPL class from QWidgetPrivate, not that it's supported anyway, but I've seen code that does it. Not a good idea.
精彩评论