Results 1 to 2 of 2

Thread: QGraphicsView coordinates transformation

  1. #1
    Join Date
    Feb 2008
    Posts
    1
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QGraphicsView

    Hi,

    I'm trying to implement a calendar-like widget using the QGraphicsView and
    QGraphicsScene classes. I think they provide some very useful features, such as item collisions, for my application. The problem comes when adjusting the window size. I need to adjust the grid space for a week view (monday, tuesday,...) to the window width, without horizontal scrollbar, but not for the window height (the vertical scrollbar are ok).

    The only idea in my mind is to clear the scene and redraw the item in it,
    according to the new size (only width) of the scene. How could I do it better?
    Some idea to do this window-viewport transformation, only in horizontal?

    Thank you in advance.

  2. #2
    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

  3. 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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.