PDA

View Full Version : Qt QGraphicsView - BackgroundBrush Translate



saransiva_ps
28th September 2015, 08:30
I have created a view class derived from QGraphicsView and set the backgroundBrush as an image.
I want to translate the backgroundBrush. I have tried the following




// graphicsView derived from QGraphicsView
graphicsView->backgroundBrush().transform().translate(moveX, moveY);



But it is not transforming the background brush.

anda_skoa
28th September 2015, 08:59
QGraphicsView::backgroundBrush() returns a copy of the view's background brush.

You modify the copy, letting the brush used by the view stay unchanged.
See QGraphicsView::setBackgroundBrush() for applying a changed brush.

Cheers,
_

saransiva_ps
28th September 2015, 11:17
Thanks for the reply. I have tried the following in the timer update




tx += 0.2f;
ty += 0.5f;

m_BackgroundBrush = graphicsView->backgroundBrush();
m_BackgroundBrush.transform().translate(tx, ty);
graphicsView->setBackgroundBrush(m_BackgroundBrush);



But the background brush is not moving.

anda_skoa
28th September 2015, 13:28
Now you are modifying a copy of the QTransform object of QBrush.

Cheers,
_