Hi,

you have to use option->rect and implement the pure virtual function boundingRect()!

Qt Code:
  1. class LayoutItem : public QGraphicsWidget {
  2. public:
  3. LayoutItem(QGraphicsItem *parent = 0) : QGraphicsWidget( parent ) {}
  4. void paint(QPainter *painter, const QStyleOptionGraphicsItem *option,
  5. QWidget *widget = 0) {
  6.  
  7. qDebug() << "LayoutItem::paint, size = " << option->rect;
  8. painter->drawRect( option->rect );
  9. }
  10. QRectF boundingRect() const
  11. {
  12. return QRectF(0,0,400.0,400.0);
  13. }
  14.  
  15. };
  16.  
  17. class Window : public QGraphicsWidget {
  18. public:
  19. Window(QGraphicsWidget *parent = 0)
  20. {
  21. QGraphicsGridLayout *grid = new QGraphicsGridLayout( this );
  22. LayoutItem* item = new LayoutItem;
  23. grid->addItem(item, 0, 0, 1, 1);
  24. }
  25. };
To copy to clipboard, switch view to plain text mode