Results 1 to 2 of 2

Thread: Fixed QGraphicsScene in view

  1. #1
    Join Date
    Apr 2009
    Location
    Valencia (Spain)
    Posts
    245
    Thanks
    38
    Thanked 19 Times in 19 Posts
    Qt products
    Qt4
    Platforms
    Symbian S60

    Default Fixed QGraphicsScene in view

    Hi,

    by default, when we add an item in a QGraphicsScene the view tries to center it. If we add one more it tries to center both... I'd like to have it "static", a viewport unable to move.

    In order to do that I set the size of the scene to the view:

    Qt Code:
    1. //Scene
    2. pScene = new QGraphicsScene(ui->view);
    3. pScene->setSceneRect(0, 0, ui->view->width(), ui->view->height());
    4. //View
    5. ui->view->setInteractive(false);
    6. ui->view->setScene(pScene);
    7.  
    8.  
    9. QGraphicsTextItem* txtG = pScene->addText("G");
    10. txtG->setPos(0, 0);
    11. QGraphicsTextItem* txtD = pScene->addText("D");
    12. txtD->setPos(110, 110);
    To copy to clipboard, switch view to plain text mode 

    It solves the problem, but the coordinates seem to be wrong, 0, 0 should be corner top-left and it's close to the view's center.

    Does anybody know how I can solve this problem or any other way to "fix the viewport"?

    thanks!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Fixed QGraphicsScene in view

    If I were you, I'd check if ui->view->width() and ui->view->height() return values you expect since if you call this code before the window is first shown, they are likely to have bogus values (as of course explained in the docs).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 0
    Last Post: 23rd November 2011, 22:38
  2. How to fixed the size of the QGraphicsScene.?
    By syclopse in forum Qt Programming
    Replies: 9
    Last Post: 4th July 2011, 14:41
  3. Replies: 6
    Last Post: 14th September 2010, 23:18
  4. Problems with setCursor in QGraphicsScene/View
    By lightning2911 in forum Qt Programming
    Replies: 3
    Last Post: 26th August 2010, 12:04
  5. how can I have a fixed overlay layer in a View ?
    By Jaymz in forum Qt Programming
    Replies: 4
    Last Post: 18th November 2009, 16:39

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.