views:

59

answers:

3

Greetings all,

As seen in the picture

http://i51.tinypic.com/2r56s1j.jpg

I have an extended QWidget object (which draws the cell images and some countour data) inside a QScrollBar. User can zoom in/out the Image (QWidget size is changed according to the zoomed size of the QImage ) using mouse wheel.

I process the events (mouseMoveEvent(),wheelEvent()..etc) by implementing the listener methods in QWidget. My problem is ,I can only perform zooming (and other events) when the mouse pointer is over the QWidget. If the mouse point is over the QScrollBar (the gray area in the image) ,those events are consumed by the QScroolBar.

Any tips,

[Edit] Sorry I was refering to QScrollArea , not QScrollBar.

thanks, umanga

+2  A: 

I recommend you use QGraphicsScene and QGraphicsView. The graphics framework already provides a lot of useful features (including viewport transformation). And the QGraphicsView is a scroll area.

Cătălin Pitiș
A: 

have you done grabMouse() for Qwidget i.e for the one which you display image?

Shadow
yes I tried it,If I call grabMouse() other controls are not responsive.
umanga
are you ignoring the events which you are receiving at QScrollArea. i mean to say event->ignore()
Shadow
+1  A: 

I'm uncertain if you want the scroll wheel to only ever be used for zooming the image or if you want the scroll wheel to control zooming when the image is smaller than the scroll area viewport and then use the scroll wheel to do scrolling when the image is larger than the scroll area viewport. In either case, you should be able to customize how the wheel is handled with the following:

Since I've not actually tried this one, I'm not sure if it will work. The hope is that if you install an event filter and set ignore on the event, the event will still be propagated back to your image widget. This will allow you to leave your current mouse handling in the image widget intact.

bool YourImageWidget::eventFilter(QObject *obj, QEvent *event)
{
    if((obj == scrollAreaPointer) && (event->type() == QEvent::Wheel))
    {
        if(!scrollAreaShouldHandleWheel)
        {
            event->ignore();
        }
    }
    return false; // always pass the event back to the scroll area
}

The scrollAreaShouldHandleWheel flag is a boolean you would set from your image widget based on whether or not you want the scroll area to handle the wheel events.

Somewhere in your code you would install your image widget as an event filter for the scrollarea.

scrollArea->installEventFilter(imageWidget);

If this doesn't work, you can always use this filter to make sure your widget gets the event and handle it directly and then return true so that the scroll area won't be able to receive the event.

Arnold Spence
Arnold ,thanks alot for your answer.I will try this out.
umanga