Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    OpenGL/Qt Quick Scene Graph and mouse interaction

    QML and Qt Quick
    2
    5
    1866
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • M
      maksim1979 last edited by

      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":http://qt-project.org/doc/qt-5.1/qtquick/scenegraph-customgeometry.html)
      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,
      Maxim

      1 Reply Last reply Reply Quote 0
      • frederik
        frederik last edited by

        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.

        1 Reply Last reply Reply Quote 0
        • M
          maksim1979 last edited by

          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?

          1 Reply Last reply Reply Quote 0
          • M
            maksim1979 last edited by

            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);
            setAcceptedMouseButtons(Qt::LeftButton);
            setAcceptHoverEvents(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?

            1 Reply Last reply Reply Quote 0
            • M
              maksim1979 last edited by

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

              1 Reply Last reply Reply Quote 0
              • First post
                Last post