Animated widget , what s the best approach?
-
Hi everyone , I have been using pyqt and pyside for couple of years now and lately qt aswell.
So I am trying to make more interactive uis and the specific goal I have for now is to have some animations in the widgets , for example one would be having a qlistWidget and when I am drag and dropping in the widget I would like the other widget for example to separate a little , in order to give a nicer feedback on where I would like to drop my widget. What s best way to implement this kind of animation in qt? What approach would you guys take?
Or any suggestion about how implement more general animation for wiget like button pressing and so on would be totally aprreciated.Thanks a lot everyone! see ya around in the community
-
Hi,
You should first have a look at the various Drag & Drop examples from Qt's documentation they should provide you with some good knowledge to get started.
-
[quote author="SGaist" date="1381954268"]Hi,
You should first have a look at the various Drag & Drop examples from Qt's documentation they should provide you with some good knowledge to get started.[/quote]
Hi man thanks for your answer , I already did and implemented my custom drag and drob using custom widget and using QMime as translator and all that just work fine , but let s say I start a drag and drop obtion so I have my custom widget being dragged in the QListWidget for example I am moving it from bottom to top mean while passing ovver all the other widget in the list . What I would like to achieve is that if my widget is between widget X and Y i would like those to slide a little away and make a small gap between the two so to give a visual nice hint to the user that if I drop now my widget will end up there.
I mean it s purely an aestetic feature , nothing to do with actual functionality of drag and drop. -
There's something that is not really clear, do you want items in a QListWidget to move or e.g. move your dragged element between two labels and they should move ?
-
Maybe you could take a look into the sources of QMainWindow? Somewhere in there (or probably in a related private class) is a function that animates things like QToolBars or QDockWidgets being dragged around in the QMainWindow. I haven't looked at the code myself, but the animations are very well done, so maybe you can help yourself by learning from the readily available sources.
I would suggest using a layout with a special "dummy"-widget, that indicates the drop-location. You could then add that dummy at the cursors position (keeping the UI snappy could be tedious, since the drag operation is modal as far as I know), which should automatically move around all the other elements. If you pick a suitable layout, this could actually be relatively painless.
-
If you are hard coding the widget positions (not using a layout) you can use QPropertyAnimation on size and pos properties to get the result you want.
If you are using a layout you should subclass it and reimplement the setgeometry method so that it will use QPropertyAnimation when resizing and positioning widgets