Unsolved QGraphicsView shifted its contents when scrollbar appear
-
I noticed that QGraphicsView shifted its contents by few pixels upward when scrollbar appear. Is there anyway to avoid such behavior?. I want the scrollbar appear but the contents should stay at the same position.
Here is the sample codes:
QApplication a(argc, argv); QGraphicsView v; QGraphicsScene scene; v.show(); v.setScene(&scene); QBrush brush(Qt::red); scene.addRect(0,0,1000,80,QPen(),brush); //When you reduce the width of v, scrollbar appear but contents shifted upward. return a.exec();
I will be very appreciated if someone could help.
-
The easiest solution is to always show the scrollbars, if that is acceptable:
_myGraphicsView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn); _myGraphicsView->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
Otherwise I guess you won't have any other option besides manually translating the viewport.
-
Thanks for your suggestion.
How would I manually translate the view port ?
A snippet could help. Thanks