Hello,
I'm having some problems with the implementation of these classes,
What I'm doing so far is I have a MainWindow and the window will have a QVBoxLayout. So basically this window will be divided by two vertically. I make two QWidgets and put each widget in the layout.
I want to set one image in the top half and another image in the Bottom half. So for this I created a QGraphicsView class that has a scene and an item derived from QGraphicsItem.
So I have in QMainWindow class:
...
scene->setScenRect(0,0,topWidget.width(), topWidget->height());
item = new GrItem(scene);
scene->addItem(item);
grView->setScene(scene);
...
...
topWidget = new QWidget;
bottomWidget = new QWidget;
grView = new QGraphicsView(topWidget);
scene = new QGraphicsScene(this);
scene->setScenRect(0,0,topWidget.width(), topWidget->height());
item = new GrItem(scene);
scene->addItem(item);
grView->setScene(scene);
...
To copy to clipboard, switch view to plain text mode
Here I pass topWidget as the parent to the GraphicsView class so that it will contain the view widget. GrItem is a class derived from QGraphicsItem. I pass the scene as a parameter to be able to get the size of the sceneRect and in the paint method do :
...
painter->drawImage(sceneRect, myImage);
...
painter->drawImage(sceneRect, myImage);
To copy to clipboard, switch view to plain text mode
And after I set the layout:
mainLayout->addWidget(topWidget);
mainLAyout->addWidget(bottomWidget);
setLayout(mainLayout);
mainLayout = QVBoxLayout;
mainLayout->addWidget(topWidget);
mainLAyout->addWidget(bottomWidget);
setLayout(mainLayout);
To copy to clipboard, switch view to plain text mode
The problem I'm having is that only a portion of the image is getting drawn instead of the whole image getting drawn scaled to the size of the topWidget.
My question is where do I have to do the image sizing handling to display the whole image in this case in the whole top half of the mainwindow? I can't give setSceneRect a fixed QRecF because I also want to be able to resize the topWidget and bottomWidget and have the image always occupy the whole area of the widget that is containing the image. And since I am using layouts I don't set the size of the widgets beforehand. Also how do I properly set parent child relationships between GraphicsView, GraphicsScene and GraphicsItem?
Could someone please give me some guidance I would really appreciate it.
Thanks!
Bookmarks