Results 1 to 10 of 10

Thread: QGraphicsItem paint not triggered

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2011
    Posts
    20
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QGraphicsItem paint not triggered

    This is my paint method. What I'm really trying to do here is a movable legend. As you can see the pen size is way off but any less than 200 is not visible so my guess is that I've mixed up the maybe the scene's coordinatesystem with the item's?

    Qt Code:
    1. void itemSymbols::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
    2. {
    3. painter->setRenderHint(QPainter::Antialiasing);
    4. qDebug("itemSymbols paint()");
    5.  
    6. bBox.setHeight(height);
    7. bBox.setWidth(width);
    8.  
    9. QPointF header;
    10. header.setX(width/2);
    11. header.setY(height*0.05);
    12.  
    13. qreal newHeight = header.y();
    14.  
    15. QFont font;
    16. font.setBold(true);
    17. painter->setFont(font);
    18.  
    19. QPen pen;
    20. pen.setWidth(200);
    21. painter->setPen(pen);
    22.  
    23. painter->drawText(header,"Symbols");
    24.  
    25. qreal iRows = (height-newHeight)/15;
    26. qreal h = iRows;
    27.  
    28. qreal iCol = width/4;
    29. qreal c = iCol;
    30.  
    31. font.setBold(false);
    32. painter->setFont(font);
    33.  
    34. QFont font2;
    35. font2.setPointSizeF(4);
    36. painter->setFont(font2);
    37.  
    38. for(int i = 0;i<vPics.size();i++)
    39. {
    40. p.setX(10.0);
    41. p.setY(h+10);
    42.  
    43. QPointF p2;
    44. p2.setX(60.0);
    45. p2.setY(h);
    46.  
    47. h = h + iRows;
    48. c = c + iCol;
    49.  
    50. QPixmap pixmap(vPics.at(i));
    51. QRectF d = QRectF(p.x(),p.y(),28,28);
    52. //painter->drawRect(d);
    53. //painter->drawPixmap(p,pixmap);
    54.  
    55. const char *chTemp;
    56. chTemp = vDesc.at(i).toAscii();
    57. QRectF t = QRectF(p2.x(), p.y(),120,30);
    58. //painter->drawRect(t);
    59. //painter->drawText(QRectF(p2.x(), p.y(),120,30), Qt::AlignCenter, QObject::tr(chTemp));
    60. }
    61.  
    62. qDebug("Drawing a box at pos %f %f", bBox.topLeft().x(), bBox.topLeft().y());
    63. painter->drawRect(bBox);
    64. painter->drawPoint(centerPos);
    65. }
    To copy to clipboard, switch view to plain text mode 

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

    Default Re: QGraphicsItem paint not triggered

    I don't know what width and height are but changing the bounding box in the paint routine is definitely a bad idea. The method is called paint() and not paintAndUpdateBoundingBox(). Not knowing the scene size and the transformation matrix of the view I'm unable to say anything about the pen size.
    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: 3
    Last Post: 28th September 2010, 10:48
  2. Replies: 4
    Last Post: 30th August 2010, 14:37
  3. OpenGL functions in QGraphicsItem::paint
    By Lendrick in forum Qt Programming
    Replies: 1
    Last Post: 21st June 2010, 17:30
  4. Qgraphicsitem parent/child paint problem.
    By repka3 in forum Qt Programming
    Replies: 1
    Last Post: 24th July 2009, 22:03
  5. Paint QGraphicsItem problem
    By dreamer in forum Qt Programming
    Replies: 3
    Last Post: 23rd June 2008, 18:18

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
  •  
Qt is a trademark of The Qt Company.