PDA

View Full Version : Guidance needed to create a graph for which I should be able to rearrange the nodes.



MiniMe4Qt
25th March 2017, 15:08
I need to create something like this

https://www.youtube.com/watch?v=OHdc-wtSmg0

I would like to be able to represent graphs like the one in the clip indicated above and to be able to re arrange the nodes using the mouse. That zoom that you see in the clip is not a must

This would be my first attempt to work with Graphics in Qt. Can anybody point me to some tutorials or examples relevant to my task?

Note: I am a PyQt user

thank you
MM

d_stranz
26th March 2017, 00:15
You should start by looking at the "elastic nodes (http://doc.qt.io/qt-5/qtwidgets-graphicsview-elasticnodes-example.html)" example in the Qt distribution. It's in C++, but you could use that as a starting point. If you Google for that you'll see that there is a YouTube video of a PyQt version (without source code, of course). There are many other examples as part of the Qt Graphics-View framework.

MiniMe4Qt
26th March 2017, 09:45
Thanks a lot! That really helped
If anyone else is interested here are two examples

https://gist.github.com/reusee/2406975
http://ftp.ics.uci.edu/pub/centos0/ics-custom-build/BUILD/PyQt-x11-gpl-4.7.2/examples/graphicsview/elasticnodes.py <--lacks the edges but if you move the nodes they stick to that position. The first example has edges but when you move a node it moves the other connected nodes too

d_stranz
26th March 2017, 16:34
Yes, the Qt Elastic Nodes example is supposed to demonstrate the graphics / view framework and the animation framework, so it uses animation and simulated springs to move connected nodes and then return them to an equilibrium position after the arrangement is disturbed by moving one of them.

MiniMe4Qt
26th March 2017, 21:52
Yes, the Qt Elastic Nodes example is supposed to demonstrate the graphics / view framework and the animation framework, so it uses animation and simulated springs to move connected nodes and then return them to an equilibrium position after the arrangement is disturbed by moving one of them.

I will have to find a way to change that functionality
I do not need the elastic thing, I just need the links to stick to nodes but I must be able to move nodes