开发者

How to make non-smooth / stepwise scolling in a qgraphicsview

开发者 https://www.devze.com 2023-03-12 03:12 出处:网络
I have a scene which has a basically table-like layout. Thus I\'d like it to scroll like a table... one row or column at a time. Specifically, the upper left visible item should have it\'s upper left

I have a scene which has a basically table-like layout. Thus I'd like it to scroll like a table... one row or column at a time. Specifically, the upper left visible item should have it's upper left corner in the upper left corner of the viewport, unless the scrollbars are at their maximum (in which case it is the bottom/right item that is exactly in view). Pressing an arrow key should display the next row or column in that dire开发者_开发技巧ction.

Normally that is easily achievable by inheriting QAbstractScrollArea and setting it up as appropriate, but QGraphicsView already does this. Is there someone who can think of a clever method for achieving this effect?


just override QGraphicsScene::keyPressEvent and...

  • right: move a cells width in positive x
  • left: move a cells width in negative x
  • up: move a cells height in negative y
  • down: move a cells height in positive y

you'll have to disable this movement at the ends of the table, but it sounds a lot simpler that you might have initially thought

EDIT
overload QGraphicsView::scrollContentsBy to handle the scroll bar movement. You could store the dx and dy parameters and only scroll the movement when this value is greater than the size of a cell

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号