Results 1 to 2 of 2

Thread: QGraphicsView update/paint issues

  1. #1
    Join Date
    Nov 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QGraphicsView update/paint issues

    Hi,

    I have trouble with QGraphicsView update.

    Screenshot:

    image1.jpg

    Code:

    GraphicsViewExample.tar.bz2

    I belive there is a problem with AssociItem :: Line :: paint() where I'm setting position of QGraphicsTextItem, but I have no clue how to fix it:

    Qt Code:
    1. void AssociItem::Line::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
    2. {
    3. Q_UNUSED(option);
    4. Q_UNUSED(widget);
    5.  
    6. painter->setPen(pen());
    7.  
    8. setLine(QLineF(start->mapToScene(start->boundingRect().center()),
    9. end->mapToScene(end->boundingRect().center())));
    10.  
    11. QPointF endPoint;
    12.  
    13. QPolygonF polygon = QPolygonF(end->boundingRect());
    14. QPointF p1 = polygon.first() + end->pos();
    15. QPointF p2;
    16. QLineF polyLine;
    17.  
    18. int count = polygon.count();
    19. for(int i = 1; i < count; ++i)
    20. {
    21. p2 = polygon[i] + end->pos();
    22. polyLine = QLineF(p1, p2);
    23. QLineF::IntersectType intersectType = polyLine.intersect(line(), &endPoint);
    24. if(intersectType == QLineF::BoundedIntersection)
    25. break;
    26.  
    27. p1 = p2;
    28. }
    29.  
    30. QGraphicsTextItem *text = static_cast<AssociItem *>(parentItem())->leftText;
    31. text->setPos(endPoint);
    32.  
    33. QPointF startPoint;
    34.  
    35. polygon = QPolygonF(start->boundingRect());
    36. p1 = polygon.first() + start->pos();
    37.  
    38. count = polygon.count();
    39. for(int i = 1; i < count; ++i)
    40. {
    41. p2 = polygon[i] + start->pos();
    42. polyLine = QLineF(p1, p2);
    43. QLineF::IntersectType intersectType = polyLine.intersect(line(), &startPoint);
    44. if(intersectType == QLineF::BoundedIntersection)
    45. break;
    46.  
    47. p1 = p2;
    48. }
    49.  
    50. text = static_cast<AssociItem *>(parentItem())->rightText;
    51. text->setPos(startPoint);
    52.  
    53. setLine(QLineF(startPoint, endPoint));
    54.  
    55. painter->drawLine(line());
    56. }
    To copy to clipboard, switch view to plain text mode 

    Any ideas?

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QGraphicsView update/paint issues

    paint() is supposed to paint the item inside the area specified by boundingRect(). Nothing more and certainly should not modify the object state.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 0
    Last Post: 28th November 2011, 19:03
  2. QGraphicsView : paint from an external process
    By bunjee in forum Qt Programming
    Replies: 0
    Last Post: 4th September 2010, 12:01
  3. Replies: 0
    Last Post: 18th June 2008, 11:00
  4. QGraphicsView animation issues?
    By m41n1 in forum Qt Programming
    Replies: 2
    Last Post: 6th June 2008, 07:48
  5. Replies: 1
    Last Post: 26th December 2007, 10:58

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.