View Full Version : unable to translate QGraphicsView

5th August 2009, 15:08

do I have to set a flag or anything else if I want to use QGraphicsView->translate()
or why is it not working for me although rotate, scale and shear are working well.
I also tried with QTransform and QMatrix, but I got the same result:
on setTransform and setMatrix only rotate, scale and shear are visible.
I tried different SceneRectangles as well and dont know what else to try...

thanks a lot

5th August 2009, 16:56
yes the same thing i am trying for QTransform to rotate the view but no vain ..

in Qt demo chip application

they use QMatrix only to rotate the QGraphicsView()

see in chip/view.cpp

void View::setupMatrix()
qreal scale = qPow(qreal(2), (zoomSlider->value() - 250) / qreal(50));

QMatrix matrix;
matrix.scale(scale, scale);


i dont know why they dont use QTransform

5th August 2009, 19:06

I also tried using translate() and QMatrix but what finally worked was setting the two scrollbars' value; this works even if the scrollbars are turned off:

QScrollBar* myVScrollbar;
myVScrollbar = myView->verticalScrollBar();
myVScrollbar->setValue(myVScrollbar->value() + offsetValue);

QScrollBar* myHScrollbar;
myHScrollbar = myView->horizontalScrollBar();
myHScrollbar->setValue(myHScrollbar->value() + offsetValue);

And subtract offsetValue to move in the opposite direction.

7th August 2009, 09:28

moving the scrollbars works, but it doesnt look very precisely as well..

18th January 2010, 17:42
Thank you so much for your tip !

I had the same problem, i.e. QGraphicsView::translate() not working well.
In my case, I had to call it several times to observe a change... ? I tried different SceneRect() as well.

Moving the scrollbars works perfectly for me.
Thanks again