Hi,
I'm having some trouble to resize the scene to the view size.
Here is the code:
bakgroundview.h
#ifndef BACKGROUNDVIEW_H
#define BACKGROUNDVIEW_H
#include <QObject>
#include <QGraphicsView>
#include <QGraphicsScene>
{
Q_OBJECT
public:
~BackgroundView() {};
signals:
public slots:
private:
protected:
};
#endif // BACKGROUNDVIEW_H
#ifndef BACKGROUNDVIEW_H
#define BACKGROUNDVIEW_H
#include <QObject>
#include <QGraphicsView>
#include <QGraphicsScene>
class BackgroundView : public QGraphicsView
{
Q_OBJECT
public:
BackgroundView(QGraphicsView *parent=0);
~BackgroundView() {};
signals:
public slots:
private:
QGraphicsView *view;
QGraphicsScene *scene;
protected:
void resizeEvent(QResizeEvent *event);
};
#endif // BACKGROUNDVIEW_H
To copy to clipboard, switch view to plain text mode
bakgroundview.cpp
#include <QGraphicsLineItem>
#include <QResizeEvent>
#include "backgroundview.h"
{
scene->setSceneRect(0,0,view->width(),view->height());
scene->addItem(line);
scene->addItem(line2);
scene->addItem(line3);
scene->addItem(line4);
setScene(scene);
}
{
//scene->setSceneRect(0, 0, event->size().width(), event->size().height());
}
#include <QGraphicsLineItem>
#include <QResizeEvent>
#include "backgroundview.h"
BackgroundView::BackgroundView(QGraphicsView *parent)
: QGraphicsView(parent)
{
QGraphicsView *view = new QGraphicsView();
QGraphicsScene *scene = new QGraphicsScene();
scene->setSceneRect(0,0,view->width(),view->height());
QGraphicsLineItem* line = new QGraphicsLineItem ( 0,0, scene->width(), 0 );
QGraphicsLineItem* line2 = new QGraphicsLineItem ( scene->width(), 0 , scene->width(), scene->height() );
QGraphicsLineItem* line3 = new QGraphicsLineItem ( scene->width(), scene->height(), 0, scene->height() );
QGraphicsLineItem* line4 = new QGraphicsLineItem ( 0, 0, 0, scene->height() );
scene->addItem(line);
scene->addItem(line2);
scene->addItem(line3);
scene->addItem(line4);
setScene(scene);
}
void BackgroundView::resizeEvent(QResizeEvent *event)
{
//scene->setSceneRect(0, 0, event->size().width(), event->size().height());
QGraphicsView::resizeEvent(event);
}
To copy to clipboard, switch view to plain text mode
main.cpp
#include <QApplication>
#include "backgroundview.h"
int main(int argc, char *argv[])
{
BackgroundView BgView;
BgView.showMaximized();
return app.exec();
}
#include <QApplication>
#include "backgroundview.h"
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
BackgroundView BgView;
BgView.showMaximized();
return app.exec();
}
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
Bookmarks