Important: Please read the Qt Code of Conduct -

[Solved] QGraphicsItems + QTouchEvents

  • Hi!

    Currently, I'm developing a basic application for painting on a tablet. I'm using the Qt Graphics Framework and everything works fine, except for one detail: I can't catch events when I try to draw over/inside of an existent QGraphicsItem object, specially if the first point of the new object is inside of it.

    Note: this problem only happens when I try to use Touch events, with the Mouse events it works perfect, the problem is I need to use the Touch approach to get the number of points (fingers) moving over the tablet.

    I'm handling the touch events using the method viewportEvent(QEvent *event) from a QGraphicsView based class. To create lines I'm using a QGraphicsPathItem object which follow the touch events, and the "effect" of drawing works great.

    After several tries, I found out that I can handle touch events from the inside of the QGraphicsItem based objects to deal with events "inside" of them, but it seems a little messy for me.

    The question is: Can I centralize all the events (inside and outside of the QGraphicsItem objects already contained in the QGraphicsScene) from my QGraphicsView based class without have to deal directly with the events generated from the items?

    Thank you!

  • Finally I found the solution by my own. All I had to do was to add this line in the constructor of the QGraphicsView based class:

    That's it :)

Log in to reply