Hi all, I have a small issue about QGraphicsLayout. Hope, you can show me the workaround or ma mistake here.

Code snaps:
Qt Code:
  1. Document::Document()
  2. : QGraphicsWidget(0,Qt::Window)
  3. {
  4. QGraphicsLinearLayout *layout = new QGraphicsLinearLayout(Qt::Vertical);
  5. layout->setContentsMargins(10,5,10,5);
  6. setLayout(layout);
  7. layout->addItem(new Paper(this));
  8. }
To copy to clipboard, switch view to plain text mode 
Qt Code:
  1. Paper::Paper(Document *doc, QPrinter::PaperSize paperSize, QPrinter::Orientation orientation)
  2. :
  3. ContentFrame(Qt::Vertical)
  4. {
  5. setParentLayoutItem(doc->layout());
  6. setParentItem(doc);
  7. QSizeF sizeF = printerPaperSize(orientation, paperSize, QPrinter::DevicePixel, Suzidil::DPI);
  8. setMinimumSize(sizeF);
  9.  
  10. setBrush(QBrush(QColor(255, 255, 255, 125)));
  11. setContentsMargins(30, 50, 30, 40);
  12. setName("paper");
  13.  
  14. Page *p = new Page(this);
  15. addItem(p);
  16. }
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. Page::Page(Paper *parent)
  2. : ContentFrame(Qt::Vertical, ContentFrame::ResizeAll | ContentFrame::Interactive, parent)
  3. {
  4. setName("page");
  5. setMinimumSize(100,100);
  6. setBrush(QBrush(QColor(255, 255, 255, 125)));
  7. }
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. ContentFrame::ContentFrame(Qt::Orientation orientation,
  2. ResizeOptions options,
  3. ContentFrame *parent)
  4. :
  5. QGraphicsLinearLayout(orientation),
  6. {
  7. cf_resizeOptions = options;
  8. if (!(options & NotResizable) && options & Interactive)
  9. setAcceptHoverEvents(true);
  10. setPen(QPen(Qt::NoPen));
  11. setGraphicsItem(this);
  12. setSizePolicy(QSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred));
  13. }
To copy to clipboard, switch view to plain text mode 

as u can see ContentFrame inherits both of QGraphicsLinearLayout and QGraphicsRectItem. And i want rectItem has the same geometry with the layout. So I've tried the function below.

Qt Code:
  1. void ContentFrame::setGeometry(const QRectF &rect)
  2. {
  3. QGraphicsLinearLayout::setGeometry(rect);
  4. QRectF rect2 = geometry();
  5. QGraphicsRectItem::setPos(rect2.topLeft());
  6. QGraphicsRectItem::setRect(0,0,rect2.width(),rect2.height());
  7. }
To copy to clipboard, switch view to plain text mode 

topLeft is the pos of the layout in parent's coordinates. see

I'm using A4 size for paper. (669.685 947.126)
Document's contentsMargin is (10,5,10,5)
Paper's contentsMargin is (30, 50, 30, 40)


Expected result is:
"page" geometry 30 50 609.685 847.126 // left top width height
"page" rect 0 0 609.685 847.126
"page" pos 30 50

"paper" geometry 10 5 669.685 947.126
"paper" rect 0 0 669.685 947.126
"paper" pos 10 5

Current result is:
"page" geometry 40 55 609.685 857.126
"page" rect 0 0 609.685 857.126
"page" pos 40 55

"paper" geometry 10 5 669.685 947.126
"paper" rect 0 0 669.685 947.126
"paper" pos 10 5

As I can see, Qt's layoutengine sends a rectangle to my page which is not in paper's (parent of page) coord-sys, but document's.

How can I achieve this problem, any idea? thanks.