[Qt-interest] QgraphicsScene: best way to manage events

Oliver.Knoll at comit.ch Oliver.Knoll at comit.ch
Thu Nov 25 12:15:12 CET 2010


On 2010-11-25 Christian Christian Gagneraud wrote:

> ...
> Anyway, this solution seems to work well and is simple

It is easy, it works, it is straightforward... - that's why I've chosen that approach back then ;) (And yes, that was the time when I first learnt Qt, too ;)

To be honest I just started to use QGraphicsScene/View right now myself (in some hobby project), and it already can do a lot for you: there are certainly other approaches how you handle mouse/keyboard events within QGraphicsScene. But I think the basic idea of "forwarding the events to the active tool by calling its methods directly" is not totally wrong ;)

One design question you might still need to solve is whether to inherits from the whole QGraphicsView, as to catch events "globally", or inherit each of your objects from QGraphicsItem and catch the events on a per item basis. The later approach would be more flexible, since the item itself could decide /not/ to call the active tool, depending on its own state (e.g. when it is disabled, being transformed/scaled in some other way etc.).

Good luck,
  Oliver
--
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22






More information about the Qt-interest-old mailing list