I need use QGraphicsItem as a background, this background can be changed by the user any time.

In future I will add other items, like icons.

I'm using a 1680x1050 image, but will have to support any size.

My problem is: the image background being shown in diferent positions and sizes in FullScreen mode e maximized mode and in both cases with a wrong size and position.

mainview.h
Qt Code:
  1. MainView::MainView(QGraphicsView *parent)
  2. : QGraphicsView(parent)
  3. {
  4. view = new QGraphicsView();
  5. scene = new QGraphicsScene(0,0,QApplication::desktop()->width(),QApplication::desktop()->height());
  6.  
  7. Background *bg = new Background();
  8. scene->addItem(bg);
  9. setScene(scene);
  10.  
  11. setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
  12. setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
  13. setViewportUpdateMode(FullViewportUpdate);
  14. setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform | QPainter::TextAntialiasing);
  15. }
  16.  
  17. void MainView::resizeEvent(QResizeEvent *event)
  18. {
  19. QGraphicsView::resizeEvent(event);
  20. fitInView(scene->sceneRect(), Qt::IgnoreAspectRatio);
  21. scene->setSceneRect(0,0, view->width(), view->height());
  22. }
To copy to clipboard, switch view to plain text mode 


mainview.cpp
Qt Code:
  1. class MainView : public QGraphicsView
  2. {
  3. Q_OBJECT
  4. public:
  5. MainView(QGraphicsView *parent=0);
  6. ~MainView() {};
  7.  
  8. signals:
  9.  
  10. public slots:
  11.  
  12. private:
  13.  
  14. protected:
  15. void resizeEvent(QResizeEvent *event);
  16. };
To copy to clipboard, switch view to plain text mode 

background.h
Qt Code:
  1. class Background : public QGraphicsItem
  2. {
  3. public:
  4. Background(QGraphicsItem *parent=0);
  5.  
  6. QRectF boundingRect() const
  7. {
  8. return QRectF(0,0,QApplication::desktop()->width(),QApplication::desktop()->height());
  9. }
  10.  
  11. private:
  12. QPixmap *backgroundImage;
  13.  
  14. protected:
  15. void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
  16. {
  17. painter->drawPixmap(boundingRect().toRect(),*backgroundImage);
  18. }
  19. };
To copy to clipboard, switch view to plain text mode 

background.cpp
Qt Code:
  1. Background::Background(QGraphicsItem *parent)
  2. {
  3. backgroundImage = new QPixmap();
  4. backgroundImage->load("C:/wallpaper.jpg");
  5. }
To copy to clipboard, switch view to plain text mode