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:

Qt Code:
  1. ...
  2. topWidget = new QWidget;
  3. bottomWidget = new QWidget;
  4.  
  5. grView = new QGraphicsView(topWidget);
  6. scene = new QGraphicsScene(this);
  7. scene->setScenRect(0,0,topWidget.width(), topWidget->height());
  8. item = new GrItem(scene);
  9.  
  10. scene->addItem(item);
  11. grView->setScene(scene);
  12.  
  13. ...
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 :


Qt Code:
  1. ...
  2. painter->drawImage(sceneRect, myImage);
To copy to clipboard, switch view to plain text mode 

And after I set the layout:

Qt Code:
  1. mainLayout = QVBoxLayout;
  2. mainLayout->addWidget(topWidget);
  3. mainLAyout->addWidget(bottomWidget);
  4.  
  5. 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!