Results 1 to 2 of 2

Thread: QGraphicsLayout::geometry()

  1. #1
    Join Date
    Oct 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default QGraphicsLayout::geometry()

    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.

  2. #2
    Join Date
    Oct 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsLayout::geometry()

    I found my mistake, changed setGeometry function like this:
    Qt Code:
    1. void ContentFrame::setGeometry(const QRectF &rect)
    2. {
    3. QGraphicsLinearLayout::setGeometry(rect);
    4. QGraphicsRectItem::setRect(geometry());
    5. }
    To copy to clipboard, switch view to plain text mode 

    and when I put an item inside the page, for example at pos (0,0) It is corner of Document, but It looks I should consider topLeft of ContentFrame when putting an item. Solved. Thanks.

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.