Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to create weighted graph in graphicsview
Forum Updated to NodeBB v4.3 + New Features

How to create weighted graph in graphicsview

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 1.2k Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    Kalidian
    wrote on last edited by Kalidian
    #1

    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.

    2019-11-15 12;31;21.PNG

    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..

    2019-11-15 12;37;02.PNG

    GraphicsScene should be applied in GraphicsView widget. Because I want make gui like picture.
    Thank you.

    Pablo J. RoginaP 1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi and welcome to the forums

      Your description reminded me of
      https://doc.qt.io/Qt-5/qtwidgets-graphicsview-elasticnodes-example.html
      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. :)

      K 1 Reply Last reply
      3
      • K 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.

        2019-11-15 12;31;21.PNG

        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..

        2019-11-15 12;37;02.PNG

        GraphicsScene should be applied in GraphicsView widget. Because I want make gui like picture.
        Thank you.

        Pablo J. RoginaP Offline
        Pablo J. RoginaP Offline
        Pablo J. Rogina
        wrote on last edited by
        #3

        @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.

        Good coding!

        Upvote the answer(s) that helped you solve the issue
        Use "Topic Tools" button to mark your post as Solved
        Add screenshots via postimage.org
        Don't ask support requests via chat/PM. Please use the forum so others can benefit from the solution in the future

        1 Reply Last reply
        4
        • mrjjM mrjj

          Hi and welcome to the forums

          Your description reminded me of
          https://doc.qt.io/Qt-5/qtwidgets-graphicsview-elasticnodes-example.html
          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. :)

          K Offline
          K Offline
          Kalidian
          wrote on last edited by
          #4

          @mrjj Thank you for the reply!

          mrjjM 1 Reply Last reply
          0
          • K Kalidian

            @mrjj Thank you for the reply!

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @Kalidian
            Hi
            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.

            1 Reply Last reply
            1

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved