PDA

View Full Version : QGraphicsScene::drawForeground()



alpinista
20th November 2009, 08:29
How to make the QGraphicsScene to redraw it's foreground?

I've tried:
QGraphicsView::invalidateScene()
QGraphicsView::updateSceneRect()
QGraphicsScene::invalidate()
QGraphicsScene::update()

but it only calls QGraphicsView::drawForeground(), and never the QGraphicsScene::drawForeground(). Can someone tell me where can be the problem? Thanks ...

Tomas

yogeshgokul
20th November 2009, 08:44
How to make the QGraphicsScene to redraw it's foreground?
I've tried:
QGraphicsView::invalidateScene()
QGraphicsView::updateSceneRect()
QGraphicsScene::invalidate()
QGraphicsScene::update()
but it only calls QGraphicsView::drawForeground(), and never the QGraphicsScene::drawForeground(). Can someone tell me where can be the problem? Thanks ..
How do you know that QGraphicsScene::drawForeground() is never getting called ?

alpinista
20th November 2009, 08:55
How do you know that QGraphicsScene::drawForeground() is never getting called ?


I have my own scene class derived from QGraphicsScene, with reimplemented drawForeground() and some printf() inside ...

wysota
20th November 2009, 08:59
Do you have CONFIG+=console in your project file? Did you make sure the signature of the method is identical to the original one?

alpinista
20th November 2009, 09:10
Do you have CONFIG+=console in your project file? Did you make sure the signature of the method is identical to the original one?

yeah, i'm pretty sure about it ... but anyway, QGraphicsView::drawForeground() and QGraphicsView::drawBackground() are called allways, no matter which layer is set when calling QGraphicsScene::invalidate(). That's strange, isn't it?

scascio
20th November 2009, 09:22
Hi

Are your sure you set the scene for the graphicsview with QGraphicsView::setScene ?

wysota
20th November 2009, 09:26
No, it's not strange. If something is modified on the scene, the background and foreground need to be repainted as well. You do want to see them, right? If you only repainted the layer that changed, you wouldn't see the other two layers because... they would not be painted.

Please provide some code so that we can see if you didn't do any mistakes.

alpinista
20th November 2009, 09:45
ok .. here's the code:

scene class (not complete..):


/**
*
*
*/
class CScene : public QGraphicsScene
{
Q_OBJECT

public:
CScene(QObject* parent = NULL);
~CScene();

CViewHelper* getHelper();
CViewMarker* getMarker();

void clearAll(void);
void clearSelected(void);
void clearAuxiliary(void);

void print(QPrinter* printer);
bool isPrinting(void);


protected:
virtual void drawForeground(QPainter* painter, const QRectF & rect);
virtual void drawBackground(QPainter* painter, const QRectF & rect);



private:

CViewHelper* _helper;
CViewMarker* _marker;

// and some other private attributes ...

};



the definition of drawForeground:


void CScene::drawForeground(QPainter* painter, const QRectF & rect)
{
printf(" >>>> SCENE ---> draw foreground\n");

// draw helper
if (_helper->isEnabled())
_helper->draw(painter);

// draw marks
if (_marker->isEnabled())
_marker->draw(painter);
}



I'am trying to redraw scene foreground by mouse move event (just now, for debugging). CGView is derived from QGraphicsView.


void CGView::mouseMoveEvent(QMouseEvent *event)
{
_ddirector->mouseMove(event);

scene()->invalidate(scene()->sceneRect(), CScene::ForegroundLayer);
}


anyway, thanks for trying me to help ...

wysota
20th November 2009, 12:30
And how come (apart from the printf) you know the method is not called? BTW. Call update() instead of invalidate and see if anything changes.

alpinista
20th November 2009, 12:42
And how come (apart from the printf) you know the method is not called?

I know it, becouse the _helper->draw() or _helper->isEnabled() (see the code) are not called too .. And I also use the breakpoints.

And QGraphicsScene::update() doesn't change anything

jano_alex_es
20th November 2009, 12:48
I'm absolutly lost with your problem... have you tried rebuilding the project? :S

alpinista
20th November 2009, 13:06
I think I know what's wrong. I have also reimplemented QGraphicsView::drawForeground() and I didn't know that this is the method which actually calls QGraphicsScene::drawForeground(). Am I right?

So I would like to close this thread and thank to everyone for help
Have a nice weekend :)