A Simple Qt Graph Visualizer using OGDF

I wanted to learn about visualizing graphs, and found Open Graph Drawing Framework (OGDF).  OGDF is a sophisticated library, and provides numerous ways to layout graphs and edges. I don’t know much about graph theory, and OGDF is not well documented, so I’m far from understanding how to take full advantage.  But it is definitely a useful library, so I thought I’d share what I’ve learned so far.

You can find the source for this simple example on GitHub.

I wrote a quick and dirty Qt program that allows you to add as many nodes and edges as you like (by editing mainWindow.cpp).  The labels are automatically generated. Here’s how a simple arbitrary graph looks:



OGDF allows you to make various node shapes (ellipse, triangle, hexagon, etc.).  I just stuck with the default node shape type: rectangle.

The GraphView widget (graphView.h) inherits from QGraphicsView and adds some public methods:

class QSize;
class QGraphicsScene;

class GraphView : public QGraphicsView
GraphView(QWidget* parent=0);

ogdf::node addNode(const QSize& size);
void addEdge(const ogdf::node& source, const ogdf::node& target);
void drawArrow(const QPointF& start, const QPointF& end, const QColor& color);
void layout();



method returns an ogdf::node that can be recorded and used to create an edge with



The graph shown above is created in the MainWindow constructor.

The nodes and edges are laid out and rendered by the call to


I hope to add more to this: reading/writing GML files, handling more shapes, brushes, pens, and other OGDF attributes.