Thanks for your engagement, but I don't seen go get anywhere.
I managed to implement a subclass of QGraphicsItem, but it does not draw, I have no idea why. Could you help me?
Qt Code:
  1. #ifndef SHAPEITEM_H
  2. #define SHAPEITEM_H
  3.  
  4. #include <QtGui>
  5. #include <QGraphicsItem>
  6. #include <QObject>
  7.  
  8. class ShapeItem : public QGraphicsItem
  9. {
  10.  
  11. public:
  12. ShapeItem(void);
  13. ShapeItem(const QRect *rect);
  14. ShapeItem(const QPolygon *poly);
  15.  
  16. QRectF boundingRect() const;
  17. QPainterPath shape(void) const;
  18.  
  19. virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
  20. QWidget *widget);
  21. private:
  22.  
  23. int x0,y0,x1,y1,x2,y2,x3,y3;
  24. int xmin,ymin,xmax,ymax;
  25. };
  26.  
  27. #endif
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. #include "shapeitem.h"
  2.  
  3. ShapeItem::ShapeItem(const QRect *rect)
  4. {
  5. x0 = rect->x();
  6. y0 = rect->y();
  7.  
  8. x1 = rect->x() + rect->width();
  9. y1 = y0;
  10.  
  11. x2 = x1;
  12. y2 = y0 + rect->height();
  13.  
  14. x3 = x0;
  15. y3 = y2;
  16.  
  17. xmin = x0;
  18. xmax = x1;
  19. ymin = y0;
  20. ymax = y2;
  21.  
  22. }
  23.  
  24. ShapeItem::ShapeItem(const QPolygon *poly)
  25. {
  26. poly->point(0,&x0,&y0);
  27. poly->point(1,&x1,&y1);
  28. poly->point(2,&x2,&y2);
  29. poly->point(3,&x3,&y3);
  30.  
  31. xmin = xmax = x0;
  32. ymin = ymax = y0;
  33.  
  34. if(x1<xmin) xmin = x1;
  35. if(x2<xmin) xmin = x2;
  36. if(x3<xmin) xmin = x3;
  37.  
  38. if(y1<ymin) ymin = y1;
  39. if(y2<ymin) ymin = y2;
  40. if(y3<ymin) ymin = y3;
  41.  
  42. if(x1>xmax) xmax = x1;
  43. if(x2>xmax) xmax = x2;
  44. if(x3>xmax) xmax = x3;
  45.  
  46. if(y1>ymax) ymax = y1;
  47. if(y2>ymax) ymax = y2;
  48. if(y3>ymax) ymax = y3;
  49.  
  50. }
  51.  
  52.  
  53. ShapeItem::boundingRect() const
  54. {
  55. qreal penWidth = 1;
  56. return QRectF(xmin - penWidth / 2, ymin - penWidth / 2,
  57. xmax + penWidth / 2, ymax + penWidth / 2);
  58. }
  59.  
  60. ShapeItem::shape() const
  61. {
  62. path.addRect(boundingRect());
  63. return path;
  64. }
  65.  
  66.  
  67. void
  68. ShapeItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
  69. QWidget *widget)
  70. {
  71. painter->drawLine ( x0,y0,x1,y1 );
  72. painter->drawLine ( x1,y1,x2,y2 );
  73. painter->drawLine ( x2,y2,x3,y3 );
  74. painter->drawLine ( x3,y3,x0,y0 );
  75. }
To copy to clipboard, switch view to plain text mode 

Not at all optimized, as soon as it draws me anything in the scene, I will test different variants. At this stage, numItems=0 in myQGraphicsItems::drawIntems, so I'm stuck.

I am using it lile this:
Qt Code:
  1. ShapeItem item(&outRect);
  2. scene->addItem(&item);
  3. //scene->addRect(outRect,solidBlue);
To copy to clipboard, switch view to plain text mode 

The commented-out line draws as it should, while the active lines does not.