Results 1 to 11 of 11

Thread: Is QGraphicsScene::sceneRect the actual size of the scene or is it just a ViewPort

  1. #1
    Join Date
    Jul 2012
    Posts
    201
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Is QGraphicsScene::sceneRect the actual size of the scene or is it just a ViewPort

    Hi guys, I am a bit confused by what QGraphicsScene::setSceneRect() actually does. Does it define the size of the scene or does it just define the area where the GraphicsItems can be viewed. If its the latter, I am interested in displaying QGraphicsItems that are not visible within the sceneRect one item at a time, how do I go about this. And lastly when loading items in the scene how do I make sure that NOT all items are displayed in the sceneRect, as I want to display them one item at a time at the click of a button.

    thanking you in advance.

  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: Is QGraphicsScene::sceneRect the actual size of the scene or is it just a ViewPor

    Quote Originally Posted by ayanda83 View Post
    Hi guys, I am a bit confused by what QGraphicsScene::setSceneRect() actually does. Does it define the size of the scene or does it just define the area where the GraphicsItems can be viewed.
    They are the same value.

    If its the latter, I am interested in displaying QGraphicsItems that are not visible within the sceneRect
    What does that mean?

    And lastly when loading items in the scene how do I make sure that NOT all items are displayed in the sceneRect, as I want to display them one item at a time at the click of a button.
    Hide the remaining items.
    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.


  3. #3
    Join Date
    Jul 2012
    Posts
    201
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Is QGraphicsScene::sceneRect the actual size of the scene or is it just a ViewPor

    Quote Originally Posted by wysota View Post

    Hide the remaining items.
    thank you for your reply. Hiding the items works fine but I have another QGraphicsView that must display two items from the same scene side by side. (the items are basically A5 pages with some writing on them.) And I am just curious; you said that the QGraphicsScene::sceneRect defines size of the QGraphicsScene. Each of my QGraphicsItems (i.e. A5 pages) is the same size as the sceneRect, if I add 4 of them in the scene how does the scene hold them since the scene is the same size as each of the QGraphicsItems.

  4. #4
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Is QGraphicsScene::sceneRect the actual size of the scene or is it just a ViewPor

    if I add 4 of them in the scene how does the scene hold them since the scene is the same size as each of the QGraphicsItems
    Items can be placed on top of each other, the one displayed is the one with highest z-value. Also, from the docs:
    If you restore the Z value, the item's insertion order will decide its stacking order.
    Last edited by stampede; 7th April 2015 at 16:54. Reason: reformatted to look better

  5. #5
    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: Is QGraphicsScene::sceneRect the actual size of the scene or is it just a ViewPor

    Quote Originally Posted by ayanda83 View Post
    thank you for your reply. Hiding the items works fine but I have another QGraphicsView that must display two items from the same scene side by side.
    So they are not from the same scene. Basically what you want is achievable but you shouldn't do it. I think your overall design is flawed.
    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.


  6. #6
    Join Date
    Jul 2012
    Posts
    201
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Is QGraphicsScene::sceneRect the actual size of the scene or is it just a ViewPor

    Quote Originally Posted by wysota View Post
    So they are not from the same scene. Basically what you want is achievable but you shouldn't do it. I think your overall design is flawed.
    I am going to try to be as detailed as possible about what I am trying to do and I will also include screenshots and code snippets. Below is the screenshot of the software I am trying to develop. I have also made comments on the screenshot.sceenshot1.jpg Now my aim is to have the software load all four pages in the scene at start-up and then I can just navigate from one page to the other as I please. Below is the code snippet for loading pages in the scene.
    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent) :
    2. QMainWindow(parent),
    3. ui(new Ui::MainWindow)
    4. {
    5. ui->setupUi(this);
    6. this->setWindowTitle("Elixir");
    7.  
    8. createActions();
    9. creatTextToolBar();
    10.  
    11. scene = new Scene(); // scene object
    12.  
    13. page1 = new Page(scene->sceneRect());
    14. page2 = new Page(scene->sceneRect());
    15. page3 = new Page(scene->sceneRect());
    16. page4 = new Page(scene->sceneRect());
    17.  
    18. page1->hide();
    19. page2->hide();
    20. page3->hide();
    21. page4->hide();
    22.  
    23. scene->addItem(page1);
    24. scene->addItem(page2);
    25. scene->addItem(page3);
    26. scene->addItem(page4);
    27.  
    28. //[1]
    29. ui->WorkArea_view->setScene(scene); //Linking the scence to the view
    30. ui->WorkArea_view->setRenderHint(QPainter::Antialiasing);
    31.  
    32. //[2] This is the background that holds backgrounds for the outer cover
    33. ui->backgroundsDW->setWindowTitle("Backgrounds");
    34. ui->backgroundsDW->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); //dock widget can only be docked on the left or right side of the screen.
    35. ui->backgroundsDW->hide();
    36.  
    37. //[3] This is the dockwidget that holds the background types
    38. ui->backgroundsTypeDW->setWindowTitle("Background Type");
    39. ui->backgroundsTypeDW->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
    40. ui->backgroundsTypeDW->hide();
    41.  
    42. //[4] This is the dockwidget that holds difference presentations of the imported picture.
    43. ui->photoDW->setWindowTitle("Photo");
    44. ui->photoDW->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
    45. ui->photoDW->hide();
    46.  
    47. //[5] This is the dockwidget that holds frames.
    48. ui->framesDW->setWindowTitle("Frames");
    49. ui->framesDW->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
    50. ui->framesDW->hide();
    51.  
    52. ui->backgroundsView->setModel(BackgroundsListModel::instance());
    53. ui->framesView->setModel(FramesModel::instance());
    54.  
    55. //This line connects the double clicking event to painting the background image.
    56. connect(ui->backgroundsView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(setBackgroundOnScene(QModelIndex)));
    57. }
    To copy to clipboard, switch view to plain text mode 

    @wysota, I hope this is detailed enough, and please advise where the design is flawed.

  7. #7
    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: Is QGraphicsScene::sceneRect the actual size of the scene or is it just a ViewPor

    The design is flawed where you want to display 'one page at a time' and want to use the same scene to 'display pages side by side'. They should be separate scenes unless you are fine with the first view not having scrollbars.
    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.


  8. #8
    Join Date
    Jul 2012
    Posts
    201
    Thanks
    26
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Is QGraphicsScene::sceneRect the actual size of the scene or is it just a ViewPor

    Okay so what you are saying is that there should be a scene for each of the views but how do I then stream a live feed of the work being done on the Main View if the main view is tied to its own scene. And just for clarity is the concept of adding 4 pages in the main view and being able to navigate through them at a click of a button possible. I know that the design is flawed here but I am just not sure how.

  9. #9
    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: Is QGraphicsScene::sceneRect the actual size of the scene or is it just a ViewPor

    Quote Originally Posted by ayanda83 View Post
    Okay so what you are saying is that there should be a scene for each of the views but how do I then stream a live feed of the work being done on the Main View if the main view is tied to its own scene.
    You replicate the changes in the other scene.

    And just for clarity is the concept of adding 4 pages in the main view and being able to navigate through them at a click of a button possible.
    You can do whatever you want
    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.


  10. #10
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Is QGraphicsScene::sceneRect the actual size of the scene or is it just a ViewPor

    What I suggested in a different thread by this poster on the same overall design was that if each page were a separate QGraphicsItem, then these could all be placed in the same scene. If he wants to display only one of the pages in a particular QGraphicsView, then he should set that view's scene rect to match the rect occupied by the item in the scene's scene rect. To display all of the pages in a single view, then the view's scene rect should match the scene's scene rect.

    I think part of the problem is that it looks like he has created all of the items with the same size and position in the QGraphicsScene, instead of following my suggestion to create them with a size of 1/4 the scene rect and position them side-by-side or in a 2 x 2 array. The scene rect should be sized to 4 times the page size, with the actual dimensions depending on the page arrangement.

  11. #11
    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: Is QGraphicsScene::sceneRect the actual size of the scene or is it just a ViewPor

    Hmm... I always thought that modifying the view's scene rect modifies the scene's scene rect. Well, I learned something new today
    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. QGraphicsscene.sceneRect on Windows platform
    By sanku3 in forum Qt Programming
    Replies: 0
    Last Post: 26th September 2011, 08:12
  2. QGraphicsScene's sceneRect() doesn't update
    By blooglet in forum Qt Programming
    Replies: 2
    Last Post: 17th February 2011, 09:11
  3. Viewport and scene coordinates
    By aurelius in forum Newbie
    Replies: 2
    Last Post: 30th October 2008, 23:47
  4. How to enlarge sceneRect() to the viewport size
    By iw2nhl in forum Qt Programming
    Replies: 3
    Last Post: 27th August 2007, 16:39
  5. QGraphicsScene: evolution of sceneRect
    By Pieter from Belgium in forum Qt Programming
    Replies: 2
    Last Post: 10th November 2006, 15:11

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.