Results 1 to 2 of 2

Thread: How QGraphicsScene::setSceneRect exactly works?

  1. #1
    Join Date
    Apr 2008
    Posts
    26
    Thanks
    1

    Default How QGraphicsScene::setSceneRect exactly works?

    Hello.

    I have 3 examples:

    1.
    Qt Code:
    1. mgw = MyGW::_self(this);
    2. ui->setupUi(this);
    3. this->resize(300,300);
    4. ui->verticalLayout->addWidget(mgw);
    5.  
    6. scene.setSceneRect(-700,-700,700,700);
    7.  
    8. mgw->setScene(&scene);
    9. scene.addLine(QLineF(mgw->mapToScene(0,0),mgw->mapToScene(100,0)),axisPen);
    To copy to clipboard, switch view to plain text mode 
    In this case graphicsView has long scrolls and my line starts not in top left corner of the view (as i expected) but somewhere around 80,200 point in graphicsView coordinates.

    2.
    Qt Code:
    1. mgw = MyGW::_self(this);
    2. ui->setupUi(this);
    3. this->resize(300,300);
    4. ui->verticalLayout->addWidget(mgw);
    5.  
    6. scene.setSceneRect(-100,-100,100,100);
    7.  
    8. mgw->setScene(&scene);
    9. scene.addLine(QLineF(mgw->mapToScene(0,0),mgw->mapToScene(100,0)),axisPen);
    To copy to clipboard, switch view to plain text mode 
    No scrolls in this case and line is not visible

    3.
    Qt Code:
    1. mgw = MyGW::_self(this);
    2. ui->setupUi(this);
    3. this->resize(300,300);
    4. ui->verticalLayout->addWidget(mgw);
    5.  
    6. // scene.setSceneRect(-100,-100,100,100);
    7.  
    8. mgw->setScene(&scene);
    9. scene.addLine(QLineF(mgw->mapToScene(0,0),mgw->mapToScene(100,0)),axisPen);
    To copy to clipboard, switch view to plain text mode 
    Line starts at top left corner but graphicsView has scrolls


    So I need correct painting in external coordinates and no unnecessary scrolls. But most of all i want to understand how exactly should i use setSceneRect.

    Thank you.

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How QGraphicsScene::setSceneRect exactly works?

    have you looked at the values returned by mapToScene in a debugger?

Similar Threads

  1. don't works on linux ?
    By 21did21 in forum Qwt
    Replies: 5
    Last Post: 5th September 2011, 09:28
  2. Replies: 3
    Last Post: 6th July 2011, 06:59
  3. INCLUDEPATH how it works ?
    By tonnot in forum Newbie
    Replies: 23
    Last Post: 29th October 2010, 09:53
  4. setSceneRect not being called properly?
    By bjh in forum Qt Programming
    Replies: 7
    Last Post: 12th July 2009, 19:42

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.