PDA

View Full Version : Is QGraphicsScene::sceneRect the actual size of the scene or is it just a ViewPort



ayanda83
7th April 2015, 14:52
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.

wysota
7th April 2015, 15:43
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.

ayanda83
7th April 2015, 17:22
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.

stampede
7th April 2015, 17:53
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.

wysota
7th April 2015, 23:00
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.

ayanda83
8th April 2015, 06:59
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.11062 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.
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
this->setWindowTitle("Elixir");

createActions();
creatTextToolBar();

scene = new Scene(); // scene object

page1 = new Page(scene->sceneRect());
page2 = new Page(scene->sceneRect());
page3 = new Page(scene->sceneRect());
page4 = new Page(scene->sceneRect());

page1->hide();
page2->hide();
page3->hide();
page4->hide();

scene->addItem(page1);
scene->addItem(page2);
scene->addItem(page3);
scene->addItem(page4);

//[1]
ui->WorkArea_view->setScene(scene); //Linking the scence to the view
ui->WorkArea_view->setRenderHint(QPainter::Antialiasing);

//[2] This is the background that holds backgrounds for the outer cover
ui->backgroundsDW->setWindowTitle("Backgrounds");
ui->backgroundsDW->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea); //dock widget can only be docked on the left or right side of the screen.
ui->backgroundsDW->hide();

//[3] This is the dockwidget that holds the background types
ui->backgroundsTypeDW->setWindowTitle("Background Type");
ui->backgroundsTypeDW->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
ui->backgroundsTypeDW->hide();

//[4] This is the dockwidget that holds difference presentations of the imported picture.
ui->photoDW->setWindowTitle("Photo");
ui->photoDW->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
ui->photoDW->hide();

//[5] This is the dockwidget that holds frames.
ui->framesDW->setWindowTitle("Frames");
ui->framesDW->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
ui->framesDW->hide();

ui->backgroundsView->setModel(BackgroundsListModel::instance());
ui->framesView->setModel(FramesModel::instance());

//This line connects the double clicking event to painting the background image.
connect(ui->backgroundsView, SIGNAL(doubleClicked(QModelIndex)), this, SLOT(setBackgroundOnScene(QModelIndex)));
}

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

wysota
8th April 2015, 08:53
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.

ayanda83
8th April 2015, 12:59
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.

wysota
8th April 2015, 13:59
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 :)

d_stranz
8th April 2015, 17:19
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.

wysota
8th April 2015, 19:38
Hmm... I always thought that modifying the view's scene rect modifies the scene's scene rect. Well, I learned something new today :)