Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6770135
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:16:34+00:00 2026-05-26T15:16:34+00:00

Im looking to implement an application that is working with and displaying simple graph.

  • 0

Im looking to implement an application that is working with and displaying simple graph. One of those is a tree, one is like an automaton.

I decided to use OGDF in addition to Qt, because i need layouting. But Im not quite getting this…do I have to to implement all the drawing/positioning functionality myself (like fetching all the node and edge coordinates from GraphAttributes) or does OGDF provide some nice interface for that? (as nice as GraphAttributes::writeGML())

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T15:16:35+00:00Added an answer on May 26, 2026 at 3:16 pm

    I couldn’t find any nice interface so I am just fetching the coordinates myself, however, this approach is not perfect since the layout algorithm returns negative coordinates (relative to a graph center point I think, instead of the normal topleft origin). My code looks kinda like this:

    int nodeWidth = 30, nodeHeight = 30, siblingDistance = nodeWidth + nodeHeight;
    
    ogdf::TreeLayout treeLayout;
    treeLayout.siblingDistance(siblingDistance);
    treeLayout.call(GA);
    
    int width = GA.boundingBox().width(), height = GA.boundingBox().height();
    
    ui->graphView->scene()->setSceneRect(QRect(0, 0, width+nodeWidth, height+nodeHeight));
    cout << "Scene dimensions: " << GA.boundingBox().width() << " x " << GA.boundingBox().height() << endl;
    
    GA.setAllWidth(nodeWidth);
    GA.setAllHeight(nodeHeight);
    
    ogdf::edge e;
    forall_edges(e,graph){
        ogdf::node source = e->source(), target = e->target();
        int x1 = GA.x(source), y1 = GA.y(source);
        int x2 = GA.x(target), y2 = GA.y(target);
        QPainterPath p;
        p.moveTo(x1 + nodeWidth/2, y1 + nodeHeight/2);
        p.lineTo(x2 + nodeWidth/2, y2 + nodeHeight/2);
        (void) ui->graphView->scene()->addPath(p, QPen(Qt::darkGray), QBrush(Qt::white));
    }
    
    ogdf::node n;
    forall_nodes(n, graph) {
        double x = GA.x(n);
        double y = GA.y(n);
        double w = GA.width(n);
        double h = GA.height(n);
        QRectF boundingRect(x, y, w, h);
        cout << x << " : " << y << " : " << endl;
        QRadialGradient radialGradient(boundingRect.center(), boundingRect.width());
        radialGradient.setColorAt(1.0, Qt::lightGray);
        radialGradient.setColorAt(0.7, QColor(230,230,240));
        radialGradient.setColorAt(0.0, Qt::white);
        (void) ui->graphView->scene()->addEllipse(boundingRect, QPen(Qt::black), QBrush(QRadialGradient(radialGradient)));
        QGraphicsTextItem *text = ui->graphView->scene()->addText(QString(GA.labelNode(n).cstr()));
        text->setPos(x, y);
    }
    
    // clear the graph after it has been displayed
    graph.clear();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For an application I'm working on, I'd like to implement sort of a gauge-like
Looking to implement a RIA (rich internet application) either as a java (JWS) application
We are looking to implement Optimistic locking in our WCF/WPF application. So far the
I am looking to have a C# application implement the Konami Code to display
I am looking to implement a data-driven wizard with the question tree stored in
I am working on a Visual studio like application i.e. have a toolbox, an
In the application that I'm currently working on, it is possible for multiple users
I'm currently working on a web application that might need to push information to
I'm working on an intranet-only web application (J2EE) that requires some basic security features.
I am looking for a (small) library that helps me cleanly implement a front

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.