tags:

views:

573

answers:

2

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?

A: 

Evan Teran, sorry for that comment.

// Constructor:
GraphWidget::GraphWidget( QWidget *parent ) :
        QGraphicsView(parent),
        bounds(0, 0, 0, 0)
{
    setScene(&scene);
    QPen board_pen(QColor(255, 0, 0));
    QPen nature_pen(QColor(0, 0, 255));
    nature_path_item = scene.addPath( board_path, board_pen );
    board_path_item  = scene.addPath( nature_path, nature_pen );
}

// Eventually called func:
void GraphWidget::Redraw() {
    if(motion) {
        double nature[6];
        double board[6];
        // Get coords:
        motion->getNature(nature);
        motion->getBoard(board);
        if(nature_path.elementCount() == 0) {
            nature_path.moveTo( nature[0], nature[1] );
        } else {
            nature_path.lineTo( nature[0], nature[1] );
        }
        if(board_path.elementCount() == 0) {
            board_path.moveTo( board[0], board[1] );
        } else {
            board_path.lineTo( board[0], board[1] );
        }
    }
}
+3  A: 
wuub
The window appears.Lines are not drawn. If I add them before call to scene.addPath(), they appears, but (as in your example) GraphicsView doens't update, if I change path (new lines doesn't appear).
Oh, I think I figured out the bug... The combo board_path_item = new QGraphicsPathItem(); scene.addPath(nature_path_item->path(), nature_pen);Doen't track changes. Thanks to your sample
But the task about clipping is still open...