Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QGraphicsView: Disable automatic scrolling

I want to have a QGraphicsView that never scrolls automatically.

Similar: Basically, my question is identical to http://developer.qt.nokia.com/forums/viewthread/2220 , but that thread didn't receive an answer.

What I have tried so far:

  • Within showEvent() and resizeEvent(), I do ui->graphicsView->fitInView(...), which works fine as long as items do not overshoot the screen-rectangle
  • I've also tried manipulating the view transform, but apart from scaling it's coefficients never change, so this was fruitless, too
  • Diabling scroll bar appearance does not help, too

See also http://doc.qt.io/qt-4.8/qgraphicsview.html.

like image 825
Sebastian Mach Avatar asked Jan 14 '11 09:01

Sebastian Mach


1 Answers

My solution is a bit sketchy but I think it's pretty intuitive: If you don't want the QGraphicsView to ever scroll your stuff, override the virtual method scrollContentsBy.

void QGraphicsViewDerived::scrollContentsBy(int, int)
{
    //don't do anything hah!
}
like image 139
anonvt Avatar answered Nov 14 '22 22:11

anonvt