Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
How to create weighted graph in graphicsview
Kalidian last edited by Kalidian
Hello. Please understand that I am not good at English.
I want to make graph algorithm like this site https://graphonline.ru/en/.
I'm searching for google and this forum for one week, but I can't know how make that.
To make that, firstly I should make weighted graph like this site https://www.programiz.com/dsa/kruskal-algorithm, but I can't make that.
I want to make node(like circle) and edge(line) that will be made at mouse pressed in graphicsview widget(not static, used mousepressevent and using it's pos). And, I should know that node's label, and edge's label and weight because I will make algorithm.
If I know how to make that, I will can make adjacency list and kruskal's algorithm, etc..
GraphicsScene should be applied in GraphicsView widget. Because I want make gui like picture.
Hi and welcome to the forums
Your description reminded me of
Which i think could be a good base to start from.
The node can be dragged and it has a line class too.
ps. your english seems fine. :)
Pablo J. Rogina last edited by
@Kalidian If I may suggest, I'd say please consider separating the construction and handling of the graphs (i.e. adding edges, nodes, weights to edges) along with applying algorithms to them (Kruskal, shortest path, etc) from the graphical representation of the graph on screen.
There are a bunch of proven graph theory libraries for C++ that you can use (it's a long time since I don't use them anymore, but take a look at Boost Graph, NGraph, LEMON, you can search them) that I think may save you lot of time and effort regarding the underlying graph data structure and operations. You can also have a way to save and restore graphs already built with some of them
Once you have a data structure to support the graph in place, then you can move on to do the fancy display on the GUI.
Kalidian last edited by
@mrjj Thank you for the reply!
Np, and do please also consider @Pablo-J-Rogina very valid point that
such algorithms can be had via a library so writing one yourself might not be the best
way unless its only kruskal's you are after and the app will never need to use other algorithms.
Or its simply for learning.