Quote Originally Posted by lni View Post
In QWidget, we never have to worry about where is the parent's location, we don't care, because we know the child position is only related to its parent...
This is exactly the case with graphics items as well.

But not in QGraphicsItem, becasue all item's cordinates have the same origin, which is the scene's origin...
No, this is not true. You are simply using the item in a wrong way. QGraphicsRectItem::setRect() is not equivalent to QWidget::setGeometry()!

Substitute your testGraphicsRect() with this one:
Qt Code:
  1. static void testGraphicsRect()
  2. {
  3. // test graphics
  4. scene->setSceneRect( 0, 0, 500, 500 );
  5.  
  6. outerRect->setRect( QRectF( 0, 0, 400, 400 ) );
  7. outerRect->setBrush( QBrush( Qt::black ) );
  8.  
  9. innerRect->setRect( QRectF( 0, 0, 200, 400 ) );
  10. innerRect->setParentItem( outerRect );
  11. innerRect->setPos(5,5);
  12. innerRect->setPen( QPen( Qt::red ) );
  13. innerRect->setBrush( QBrush( Qt::red ) );
  14.  
  15. scene->addItem( outerRect );
  16. outerRect->setPos(20,20);
  17. QGraphicsView* view = new QGraphicsView(scene);
  18.  
  19. view->setWindowTitle( "testGraphicsRect" );
  20. view->show();
  21.  
  22. }
To copy to clipboard, switch view to plain text mode