views:

670

answers:

3

In my application I have QGraphicsScene with pixmap added and all is viewed in QGraphicsView with scrollbars off. The program window is smaller then pixmap and when I press arrow keys or move mouse wheel the pixmap is being moved.

How do I disable that so even if the pixmap is bigger than window it won't be moved by keyboard or mouse unless I use my events for that?

(I tried to set interactive property to false but that didn't work)

A: 

I don't know if there's an easier way, but the moderately easy way would be to make a class that inherits your QGraphicsView class, and overrides the mouse and key press events.

The harder way would involve installing an event filter on the widget.

In my opinion, the hardest brute-force solution would be to detect the change through some sort of signal, and set it back to how it was.

Caleb Huitt - cjhuitt
+2  A: 

I believe the easiest solution would be to set FocusPolicy of QGraphicsView to NoFocus and then process all key events in main window.

ui->graphicsView->setFocusPolicy( Qt::NoFocus );
Raf
A: 

I think the easy way is to use QGraphicsView::setSceneRect() to set the area that the view is allowed to visualize.

If you set the view's sceneRect() to the actual size of the view widget (or just slightly smaller), then it won't be able to scroll or pan outside of this rectangle.

Mark Boots