I have subclassed QGraphicsItem to draw a roundedRect with two lines of text in.

I would like to pass the size and the text to the item so the item can be used dynamically for a number of different items.

the code i have is below:


Qt Code:
  1. class SimpleItem : public QGraphicsItem
  2. {
  3. public:
  4.  
  5. //SimpleItem(QString Title);
  6.  
  7. QRectF boundingRect() const
  8. {
  9. qreal penWidth = 1;
  10. return QRectF(-10 - penWidth / 2, -10 - penWidth / 2,
  11. 20 + penWidth, 20 + penWidth);
  12. }
  13.  
  14. void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
  15. QWidget *widget)
  16. {
  17. painter->drawRoundedRect(-10, -10, 100, 50, 5, 5);
  18. //painter->brush(Qt::blue);
  19. //QVariant title = title;
  20. painter->drawText(10, 10, "Title");
  21. painter->drawText(10, 30, "Subtitle");
  22. }
  23. };
To copy to clipboard, switch view to plain text mode