QGraphicsView calls drawItems of the scene that is added to the view, thus your custom scene.
that's the problem... but it doesn't :S
MainWindow
::MainWindow(QWidget *parent
){
setWindowTitle("PruebaMagnetica1");
m_pScene = new CScene();
m_pView = new CView(m_pScene, this);
...
}
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
{
setWindowTitle("PruebaMagnetica1");
m_pScene = new CScene();
m_pView = new CView(m_pScene, this);
...
}
To copy to clipboard, switch view to plain text mode
View.h
{
public:
CView
(CScene
* pScene,
QWidget * parent
= 0);
virtual ~CView();
void enableRendering(){m_bRender = true;}
protected:
bool m_bRender;
};
class CView : public QGraphicsView
{
public:
CView(CScene* pScene, QWidget * parent = 0);
virtual ~CView();
void enableRendering(){m_bRender = true;}
protected:
void drawItems ( QPainter * painter, int numItems, QGraphicsItem * items[],
const QStyleOptionGraphicsItem options[] );
bool m_bRender;
};
To copy to clipboard, switch view to plain text mode
View.cpp
CView
::CView(CScene
* pScene,
QWidget * parent
){
setParent(parent);
setScene(pScene);
m_bRender = false;
}
CView::~CView()
{
// TODO Auto-generated destructor stub
}
{
if(m_bRender)
{
QGraphicsView::drawItems(painter, numItems, items, options
);
//It calls QGraphicsScene::drawItems instead of CScene::drawItems m_bRender = false;
}
}
CView::CView(CScene* pScene, QWidget * parent)
{
setParent(parent);
setScene(pScene);
m_bRender = false;
}
CView::~CView()
{
// TODO Auto-generated destructor stub
}
void CView::drawItems( QPainter * painter, int numItems, QGraphicsItem * items[], const QStyleOptionGraphicsItem options[] )
{
if(m_bRender)
{
QGraphicsView::drawItems(painter, numItems, items, options); //It calls QGraphicsScene::drawItems instead of CScene::drawItems
m_bRender = false;
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks