[commonqt-devel] Zoom in/out QGraphicsView centering on mouse position

Hi! I want to implement a AutoCAD-like zoom in/out behavior and found this: http://www.qtcentre.org/threads/35738-How-to-zooming-like-in-AutoCAD-with-QG... I tried to use scale+centerOn (also in wheel event) but it doesn't work. It is scaled properly but does NOT center on the given point. Is there any workaround? - Rujia

Rujia Liu <rujia.liu@gmail.com> writes:
Hi!
I want to implement a AutoCAD-like zoom in/out behavior and found this:
http://www.qtcentre.org/threads/35738-How-to-zooming-like-in-AutoCAD-with-QG...
I tried to use scale+centerOn (also in wheel event) but it doesn't work. It is scaled properly but does NOT center on the given point. Is there any workaround? That got to be a qt problem, unless something specific doesn't work. You'll need to paste the code to diagnose it further.
-- With best regards, Stas.

Ok! I'll look into it soon and will paste some code if I still haven't get it right. BTW: is it possible to add a mouse event handler without subclassing and override the event handler? sometimes it'll be cleaner. On Wed, Sep 18, 2013 at 9:18 AM, Stas Boukarev <stassats@gmail.com> wrote:
Rujia Liu <rujia.liu@gmail.com> writes:
Hi!
I want to implement a AutoCAD-like zoom in/out behavior and found this:
http://www.qtcentre.org/threads/35738-How-to-zooming-like-in-AutoCAD-with-QG...
I tried to use scale+centerOn (also in wheel event) but it doesn't work.
It
is scaled properly but does NOT center on the given point. Is there any workaround? That got to be a qt problem, unless something specific doesn't work. You'll need to paste the code to diagnose it further.
-- With best regards, Stas.

Rujia Liu <rujia.liu@gmail.com> writes:
Ok! I'll look into it soon and will paste some code if I still haven't get it right.
BTW: is it possible to add a mouse event handler without subclassing and override the event handler? sometimes it'll be cleaner. Nope, not possible currently.
-- With best regards, Stas.

Problem Solved. My old code only overrides QGraphicsScene's wheel event, but the default QGraphicsView's wheel event moved the scroll bar before calling the QGraphicsScene's wheel events, so the behavior messed up :-/ Now I overrided QGraphicsView's wheel event and did not call (call-next-qmethod event), now it works perfectly!!! On Wed, Sep 18, 2013 at 10:21 AM, Stas Boukarev <stassats@gmail.com> wrote:
Rujia Liu <rujia.liu@gmail.com> writes:
Ok! I'll look into it soon and will paste some code if I still haven't get it right.
BTW: is it possible to add a mouse event handler without subclassing and override the event handler? sometimes it'll be cleaner. Nope, not possible currently.
-- With best regards, Stas.
participants (2)
-
Rujia Liu
-
Stas Boukarev