Qt Forum

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

    Update: Forum Guidelines & Code of Conduct

    Enter and Leave events using QQuickItem

    QML and Qt Quick
    5
    9
    4019
    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.
    • Z
      Zamx last edited by

      Hi,

      I want to highlight my items when the mouse moves over them. So I need a way to know when the mouse enters my item and when it leaves. With QWidget I would use EnterEvent and LeaveEvent. But these nice functions don't exist for QQuickItem.

      I tried overloading HoverEnterEvent and HoverLeaveEvent, but they only partially give the result I need. When I move the mouse for a parent to a child, I still get hover events from the parent.

      Any help is appreciated.

      1 Reply Last reply Reply Quote 0
      • F
        fdrk last edited by

        You can do this easely with states, I've used it myself to render an item with opacity when the mouse is held over it:
        @
        MouseArea {
        id: delegateImgMouseArea;
        anchors.fill: parent;
        hoverEnabled: true;
        }

            states: State {
                when: delegateImgMouseArea.containsMouse;
                PropertyChanges {
                    target: delegateImg;
                    opacity: 1;
                }
            }
        

        @

        Edit: please use @ tags around code sections; Andre

        1 Reply Last reply Reply Quote 0
        • Z
          Zamx last edited by

          Thanks for your answer fdrk, but I looking for a solution in C++.

          Currently I keep a stack of current widgets I hover over, then when I receive a hover leave event I pop the stack and highlight the front of the stack. But I would like a cleaner solution.

          1 Reply Last reply Reply Quote 0
          • D
            diro last edited by

            Zamx, will you need a C++ solution?
            With MouseArea, you can call a C++ function, I think it is a cleaner and easier solution.

            1 Reply Last reply Reply Quote 0
            • L
              lgeyer last edited by

              [quote author="Zamx" date="1341403462"]I tried overloading HoverEnterEvent and HoverLeaveEvent, but they only partially give the result I need. When I move the mouse for a parent to a child, I still get hover events from the parent.[/quote]This is the default behaviour for QHoverEvent, which can be disabled by setting the Qt::WA_NoMousePropagation attribute.

              1 Reply Last reply Reply Quote 0
              • Z
                Zamx last edited by

                [quote author="diro" date="1341460818"]Zamx, will you need a C++ solution?
                With MouseArea, you can call a C++ function, I think it is a cleaner and easier solution.[/quote]

                I'm using C++, because creating a lot of custom QQuickItem's and I want them all to have the same mouse behaviour.

                [quote author="Lukas Geyer" date="1341468186"]This is the default behaviour for QHoverEvent, which can be disabled by setting the Qt::WA_NoMousePropagation attribute.[/quote]

                Can I use Qt::WA_NoMousePropagation? Because then I need to call setAttribute( ... ) which QQuickItem doesn't have.

                1 Reply Last reply Reply Quote 0
                • L
                  lgeyer last edited by

                  Well, that's actually right. Do you mind filing a "bug report":http://qt-project.org/doc/qt-5.0/bughowto.html?

                  1 Reply Last reply Reply Quote 0
                  • Z
                    Zamx last edited by

                    [quote author="Lukas Geyer" date="1341473151"]Well, that's actually right. Do you mind filing a "bug report":http://qt-project.org/doc/qt-5.0/bughowto.html?[/quote]

                    Done. https://bugreports.qt-project.org/browse/QTBUG-26434

                    1 Reply Last reply Reply Quote 0
                    • A
                      andre last edited by

                      Could you post a link to the bugreport please?

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