Matthieu Riegler
Matthieu Riegler

Reputation: 55846

QGraphicsView artefacts

I'm having some trouble with my QGraphicsView. I've subclass the QGraphicsView to redefine paintEvent. I want to draw some kind a tree using QGraphicsItem for the nodes and QGraphicsLineItem for the edges.

void GraphicsView::paintEvent ( QPaintEvent * event ) {
if(arbre!=NULL) {
    arbre->line1->setLine(arbre->text->x(),arbre->text->y(),
                          arbre->text1->x(),arbre->text1->y());

    QGraphicsView::paintEvent(event);
    cout << "redessine" << endl;
}

}

But when a I move the nodes to fast, some artefacts (black lines) appear on the view. Any suggestion to get rid of those ?

Upvotes: 1

Views: 892

Answers (2)

weeska
weeska

Reputation: 461

Besides the misplaced logic, call QGraphicsItem::​prepareGeometryChange() before altering an objects geometry. That helped me with a similar problem.

Upvotes: 1

azf
azf

Reputation: 2189

Be sure to include a margin in the boundingRect() method of your QGraphics*Item subclasses.

http://qt-project.org/doc/qt-4.8/qgraphicsitem.html#boundingRect

PS: Don't put logic in paintEvent method. This method is used to render stuff, not to gather UI field contents or whatever (arbre->line1->setLine)

Upvotes: 1

Related Questions