Hi,

I'm having some trouble to resize the scene to the view size.

Here is the code:

bakgroundview.h
Qt Code:
  1. #ifndef BACKGROUNDVIEW_H
  2. #define BACKGROUNDVIEW_H
  3.  
  4. #include <QObject>
  5. #include <QGraphicsView>
  6. #include <QGraphicsScene>
  7.  
  8. class BackgroundView : public QGraphicsView
  9. {
  10. Q_OBJECT
  11. public:
  12. BackgroundView(QGraphicsView *parent=0);
  13. ~BackgroundView() {};
  14.  
  15. signals:
  16.  
  17. public slots:
  18.  
  19. private:
  20.  
  21. protected:
  22. void resizeEvent(QResizeEvent *event);
  23. };
  24.  
  25. #endif // BACKGROUNDVIEW_H
To copy to clipboard, switch view to plain text mode 

bakgroundview.cpp
Qt Code:
  1. #include <QGraphicsLineItem>
  2. #include <QResizeEvent>
  3.  
  4. #include "backgroundview.h"
  5.  
  6. BackgroundView::BackgroundView(QGraphicsView *parent)
  7. : QGraphicsView(parent)
  8. {
  9.  
  10. scene->setSceneRect(0,0,view->width(),view->height());
  11.  
  12. QGraphicsLineItem* line = new QGraphicsLineItem ( 0,0, scene->width(), 0 );
  13. QGraphicsLineItem* line2 = new QGraphicsLineItem ( scene->width(), 0 , scene->width(), scene->height() );
  14. QGraphicsLineItem* line3 = new QGraphicsLineItem ( scene->width(), scene->height(), 0, scene->height() );
  15. QGraphicsLineItem* line4 = new QGraphicsLineItem ( 0, 0, 0, scene->height() );
  16.  
  17. scene->addItem(line);
  18. scene->addItem(line2);
  19. scene->addItem(line3);
  20. scene->addItem(line4);
  21.  
  22. setScene(scene);
  23. }
  24.  
  25. void BackgroundView::resizeEvent(QResizeEvent *event)
  26. {
  27. //scene->setSceneRect(0, 0, event->size().width(), event->size().height());
  28. QGraphicsView::resizeEvent(event);
  29. }
To copy to clipboard, switch view to plain text mode 

main.cpp
Qt Code:
  1. #include <QApplication>
  2. #include "backgroundview.h"
  3.  
  4. int main(int argc, char *argv[])
  5. {
  6. QApplication app(argc, argv);
  7.  
  8.  
  9. BackgroundView BgView;
  10. BgView.showMaximized();
  11.  
  12. return app.exec();
  13. }
To copy to clipboard, switch view to plain text mode 

When I remove the comment from the scene resize line, the window just close realy fast with an error.

How can I resize the scene to view every time the view was resized?

Thanks