Search code examples
c++qtgraphqgraphicsview

Graph editor on Qt


I'm writing a graph editor now. The programs must be written on Qt, but the problem is that I don't have enough experience with Qt, but I'm little experienced with C++. Last weeks I read one book about Qt, but I've read about 100 pages, so I know only some basics.

Can somebody give me advices about what classes should I use, please?

What I've already done:

  • I filled menubar with menus File, Algorithms, About etc.
  • I suppose that graph vertexes etc I should draw on QGraphicsView, so I added it too, also I add QGraphicsScene and bind them together (ui->setScene(scene)).

Sorry for my mistakes, unfortunately I don't have a complete understanding about all these things.

Also I added QGraphicsRectItem with scene->addRect() and set the flag moveable. But I don't know what classes should I have to use.

So, in general I want to understand how to do next things:

  • I want to add a panel with 2 buttons (vertex, line). After I chose vertex button (or what it will be) and click on the QGraphicsView - vertex should appear at that point. Also I must be able to change vertex name
  • After I chose line mode (link, which connected 2 vertexes) I should be able to connect 2 vertexes together depending on graph type (oriented or not).
  • By clicking on link between vertexes I should be able to change the weight of link.

I think it would be enough for one question.

Sorry if the question is very simple or stupid.

Thanks.


Solution

  • Your question is rather broad so it's nearly impossible to answer it entirely. So instead, I'll offer a really good example you might go look at. This example does much of what you want and might be a good starting set of code to both look at as well as reuse.