PDA

View Full Version : use painter in QGraphicsScene::drawForeground



jano_alex_es
20th November 2009, 11:28
Hi,

I want to draw a QRectF on my graphicsScene, but I don't know why it doesn't work.



void myScene::drawBackground ( QPainter * painter, const QRectF & rect )
{
QRectF rec(m_startRectPoint, getCursorScenePos/*this function works perfectly*/());
painter->setPen(QPen(Qt::black, 1, Qt::DashLine));
painter->drawRect(rec);
update();

//QGraphicsScene::drawForeground(painter, rect);
QGraphicsScene::drawBackground(painter, rect);
}


I want to draw a rectangle which starts in "m_startREctPoint" and finishes in the mouse pointer, at each moment (I did similar things using paint event in the QGraphicsItems).
Am I doing something wrong there?

EDIT: I forgot to say something, if you minimize and maximize the widow it paints it well, as expected.

thanks!

alpinista
20th November 2009, 12:23
Hi ..

I want just ask: How do you force the scene to call your drawBackground() method? It seems that it isn't called when you move the mouse. Have you tryied QGraphicsScene::invalidate()?

By the way, I have very similar problem with drawForeground() .. :)
Please tell me, if you solve this.

jano_alex_es
20th November 2009, 12:32
Yep, now it works here. By the way, I don't force it, it's called at each moment, as far as I know as paint() event.

I just needed to move the "update()" statment after QGraphicsScene::drawBackground(painter, rect);