OpenGL/Qt Quick Scene Graph and mouse interaction

  • Hey hey

    I'm trying to implement a simple widget that will use OpenGL/Scene Graph for drawing (as described here "Scene Graph - Custom Geometry":
    But I'm not sure that I understand how to add mouse interaction here. I mean, for example I have a line and I would like to change its color when the user hover mouse cursor on it. Is it possible at all?

    Thanks a lot,

  • There are different ways to achieve this. To handle mouse interaction on the lowest level possible you will have to subclass QQuickItem and reimplement the relevant functions there. This QQuickItem can then use your custom code for painting.

    Or you expose properties on your custom item to do what you want and use regular MouseAreas to connect to these properties.

  • Thank a lot, Frederik.
    I just would like to clarify one thing. Indeed my class is inherited from QQuickItem, I put my drawing logic in the method updatePaintNode(...), so it works fine. Now I can override mouseMoveEvent method and as a result I would receive mouse events. Now let's back to my example, imagine I would like to change color/width of the drawn line/curve when mouse cursor is under it. For that I have to check that mouse cursor is located under the line, so my question, is there any functionality in Qt/OpenGL that allows to do that (I mean can I ask OpenGL to check either the point belongs to drawn figure/curve/line or not)? Or I have to do this "manually", in that case it would be not very accurate apparently since it's difficult to estimate how exactly line is drawn on the screen?

  • Strange but I have an issue with mouse events now. I've overridden mouseMoveEvent and mousePressEvent methods in my class (that is a subclass of QQuickItem), put

    setFlag(ItemHasContents, true);

    into constructor, but still don't accept mouse events.

    Update. I've noticed that I receive mouse events ONLY if I hold left mouse button. So the question how to fix that, i mean I need that events without clicking?

  • It's me again. it was a mistake from my side to use
    method. I had to use
    @void QQuickItem::hoverMoveEvent(QHoverEvent * event)@

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.