[Qt-interest] Qt-interest Digest, Vol 15, Issue 1

Kimmo Viitanen kviitanen at gmail.com
Wed Feb 1 19:06:26 CET 2012


Hi,

> I tried scribbling on the widget(ScribbleArea, available in the examples
> of Qt 4.8), then I set it to a scrollArea using
> scrollArea->setWidget(scribbleArea) and now am trying to implement
> kinetic scrolling on this scrollArea.
>
> But as you may know, when you drag the mouse vertically in bottom-top or
> top-buttom direction, the scribbleArea will receive the mouse-events
> first, and it will paint on the widget where it should actually scroll
> the image in the needed direction.
> Should I paint on the viewport of the ScrollArea without using that
> scribbleArea widget?
>
>
> I hope you understood

I cannot offer any direct help, but...

Your problem sounds a lot like the situation in all drawing 
applications: How to both draw and scroll and erase and fill etc. using 
only the left mouse button. I see a few solutions:

1. Implement a tool button that, when pressed, enters into scrolling mode.
2. If the right mouse button does nothing, make the area scroll when the 
right mouse button is pressed.
3. Make the area scroll when Ctrl (or any other key) is pressed.

etc. What every solution has in common is that you have a "scrolling 
mode" that, when activated, will scroll instead of draw. And somehow you 
have to enter that mode. You could make a double-left click exit and 
enter the scroll mode, for example. You could also make PgDn and PgUp 
scroll one view-port height for convenience.

How you would do this, is probably reimplementing mousePressEvent(). 
Then, when the left key is pressed, you check if you are in scrolling 
mode. If yes, then pass the event on to the parent of the scribble 
widget. Otherwise let the scribble widget process the event. Hopefully 
this is the right way to go.

Cheers,

Kimmo

Ps. Please change the subject when replying to digests.
Pps. You should apparently use the interest at qt-project.org mailing list 
instead.



More information about the Qt-interest-old mailing list