superwave
6th June 2011, 21:38
HI,
I want to fit an object of QGraphicsScene into the QGraphicsView and get the scene's size changed according to the object of QGraphicsView. However, I failed.
First, I defined a class derived from QGraphicsView as follows:
#ifndef IQGRAPHICSVIEW_H
#define IQGRAPHICSVIEW_H
#include <iostream>
#include <QGraphicsView>
using namespace std;
class iQGraphicsView : public QGraphicsView
{
public:
iQGraphicsView(QGraphicsScene *scene) : QGraphicsView(scene) { }
protected:
void resizeEvent(QResizeEvent *event)
{
QGraphicsView::resizeEvent(event);
fitInView(sceneRect(), Qt::IgnoreAspectRatio);
}
};
Then:
NLDCanvas = new QGraphicsScene(0,0,460,300);
iQGraphicsView* UpperLeft = new iQGraphicsView(NLDCanvas);
UpperLeft->setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
I draw the nodes and lines on the background of QGraphicsScene: that is : writing the OpenGL code in the QGraphicsScene::drawForeground
At first the showing is like this:
http://www.qtcentre.org/attachment.php?attachmentid=6543&d=1307398761
However, after changing the size of the viewport, the image inside doesn't distort and change size according to the viewport but lose some contents as below:
http://www.qtcentre.org/attachment.php?attachmentid=6542&d=1307398760
I have tested that the change of viewport doesn't change the value of sceneRect() belonging to the QGraphicsView.
I want the scene always fit inside the frame and change&distort according to the frame. What I should do?
Thanks a lot
I want to fit an object of QGraphicsScene into the QGraphicsView and get the scene's size changed according to the object of QGraphicsView. However, I failed.
First, I defined a class derived from QGraphicsView as follows:
#ifndef IQGRAPHICSVIEW_H
#define IQGRAPHICSVIEW_H
#include <iostream>
#include <QGraphicsView>
using namespace std;
class iQGraphicsView : public QGraphicsView
{
public:
iQGraphicsView(QGraphicsScene *scene) : QGraphicsView(scene) { }
protected:
void resizeEvent(QResizeEvent *event)
{
QGraphicsView::resizeEvent(event);
fitInView(sceneRect(), Qt::IgnoreAspectRatio);
}
};
Then:
NLDCanvas = new QGraphicsScene(0,0,460,300);
iQGraphicsView* UpperLeft = new iQGraphicsView(NLDCanvas);
UpperLeft->setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
I draw the nodes and lines on the background of QGraphicsScene: that is : writing the OpenGL code in the QGraphicsScene::drawForeground
At first the showing is like this:
http://www.qtcentre.org/attachment.php?attachmentid=6543&d=1307398761
However, after changing the size of the viewport, the image inside doesn't distort and change size according to the viewport but lose some contents as below:
http://www.qtcentre.org/attachment.php?attachmentid=6542&d=1307398760
I have tested that the change of viewport doesn't change the value of sceneRect() belonging to the QGraphicsView.
I want the scene always fit inside the frame and change&distort according to the frame. What I should do?
Thanks a lot