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

  • SEARCH
  • Home
  • 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 284065
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:25:36+00:00 2026-05-12T05:25:36+00:00

Mission: Draw two lines with different color on one graph with automatic cliping, by

  • 0

Mission: Draw two lines with different color on one graph with automatic cliping, by adding points bit by bit.

So, what am I doing. Create class GraphWidget, inherited from QGraphicsView. Create member of QGraphicsScene. Create 2 QPainterPath instances, and add them to graphicsScene.

Then, I eventually call graphWidget.Redraw(), where call for QPainterPath.lineTo() for both instances. And I expect appearance of that lines of graphics view, but it doesn’t.

I tired from reading Qt’s doc and forums. What am I doing wrong?

  • 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-12T05:25:36+00:00Added an answer on May 12, 2026 at 5:25 am

    We need to know more, what does not happen? Does the window appear at all? Are the lines not drawn? In the meantime try out this sample code if you want 🙂 Edit: updated to show updating.

    #include ...
    
    class QUpdatingPathItem : public QGraphicsPathItem {
        void advance(int phase) {
            if (phase == 0)
                return;
            int x = abs(rand()) % 100;
            int y = abs(rand()) % 100;
            QPainterPath p = path();
            p.lineTo(x, y);
            setPath(p);
        }
    };
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        QGraphicsScene s;
        QGraphicsView v(&s);
    
        QUpdatingPathItem item;
        item.setPen(QPen(QColor("red")));
        s.addItem(&item);
        v.show();
    
        QTimer *timer = new QTimer(&s);
        timer->connect(timer, SIGNAL(timeout()), &s, SLOT(advance()));
        timer->start(1000);
    
        return a.exec();
    }
    

    You should get something like this:

    meh...

    The path in any QGraphicsPathItem can of course be updated later. You might want to keep the original painter path somewhere to avoid performance hit caused by all the path copying (I’m not sure if QPainterPath is implicitly shared…)

    QPainterPath p = gPath.path();
    p.lineTo(0, 42);
    gPath.setPath(p);
    

    Animation

    It seems that you’re trying to do some sort of animation/on-the-fly updating. There is entire framework for this in Qt. In the simplest form you can subclass QGraphicsPathItem, reimplement its advance() slot to automatically fetch next point from motion. The only thing left to do then would be calling s.advance() with the required frequency.

    http://doc.trolltech.com/4.5/qgraphicsscene.html#advance

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My mission is to create a little app where you can upload a picture,
Let's say that I create a Sub (not a function) whose mission in life
My mission is to graduate from using PowerShell to create an instance of Outlook
We (my team) are about to start development of a mission critical project, one
So my new mission (lol). I'm looking to create a script that will rotate
In a past interview, I was asked how would I write a mission critical
This is a very basic question. I'm just on my mission to learn ASP.NET
Mission I'm trying to find out the count of children in a set of
My mission is to press a keyboard sequence, such as Ctrl + Shift +
I have next mission: i have to replace flash alement with javascript in this

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.