Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Enter and Leave events using QQuickItem
Forum Updated to NodeBB v4.3 + New Features

Enter and Leave events using QQuickItem

Scheduled Pinned Locked Moved QML and Qt Quick
9 Posts 5 Posters 4.7k Views 1 Watching
  • 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 Offline
    Z Offline
    Zamx
    wrote on last edited by
    #1

    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
    0
    • F Offline
      F Offline
      fdrk
      wrote on last edited by
      #2

      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
      0
      • Z Offline
        Z Offline
        Zamx
        wrote on last edited by
        #3

        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
        0
        • D Offline
          D Offline
          diro
          wrote on last edited by
          #4

          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
          0
          • L Offline
            L Offline
            lgeyer
            wrote on last edited by
            #5

            [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
            0
            • Z Offline
              Z Offline
              Zamx
              wrote on last edited by
              #6

              [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
              0
              • L Offline
                L Offline
                lgeyer
                wrote on last edited by
                #7

                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
                0
                • Z Offline
                  Z Offline
                  Zamx
                  wrote on last edited by
                  #8

                  [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
                  0
                  • A Offline
                    A Offline
                    andre
                    wrote on last edited by
                    #9

                    Could you post a link to the bugreport please?

                    1 Reply Last reply
                    0

                    • Login

                    • Login or register to search.
                    • First post
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved