Results 1 to 2 of 2

Thread: QGraphicsView coordinates transformation

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QGraphicsView coordinates transformation

    I think the best example is the Qt Demo application.
    Take a look at this:
    Qt Code:
    1. void MainWindow::resizeEvent(QResizeEvent *event)
    2. {
    3. this->resetMatrix();
    4. this->scale(event->size().width() / 800.0, event->size().height() / 600.0);
    5. QGraphicsView::resizeEvent(event);
    6. DemoItem::setMatrix(this->matrix());
    7.  
    8. if (this->trolltechLogo){
    9. const QRectF r = this->scene->sceneRect();
    10. QRectF ttb = this->trolltechLogo->boundingRect();
    11. this->trolltechLogo->setPos(int((r.width() - ttb.width()) / 2), 595 - ttb.height());
    12. QRectF qtb = this->qtLogo->boundingRect();
    13. this->qtLogo->setPos(802 - qtb.width(), 0);
    14. }
    15.  
    16. // Changing size will almost always
    17. // hurt FPS during the changing. So
    18. // ignore it.
    19. this->fpsHistory.clear();
    20. }
    To copy to clipboard, switch view to plain text mode 
    This is the resize event of the main window, which is also a QGraphicsView.
    The first 3 lines are the most relevant.

    Regards

  2. The following user says thank you to marcel for this useful post:

    mtribaldos (7th February 2008)

Similar Threads

  1. QGraphicsView, QGraphicsItem, QGraphicsScene
    By Shuchi Agrawal in forum Newbie
    Replies: 10
    Last Post: 23rd March 2011, 20:50

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
  •  
Qt is a trademark of The Qt Company.