Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] hover{Enter/Move/Leave}Event() events called only when QGraphicsItems is clicked
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] hover{Enter/Move/Leave}Event() events called only when QGraphicsItems is clicked

Scheduled Pinned Locked Moved General and Desktop
12 Posts 3 Posters 12.2k 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.
  • G Offline
    G Offline
    Guigui
    wrote on last edited by
    #1

    Hi all,

    I think the topic title explains most of the problem. I am trying to catch the hoverEnterEvent() on a QGraphicsItem using a pretty simple event handler:

    @void NodeItem::hoverEnterEvent(QGraphicsSceneHoverEvent *event)
    {
    Q_UNUSED(event)

    qDebug() << "Mouse entering NodeItem";
    

    }@

    However, the message appears only if I click the Item. Same happens with hoverMove and hoverLeave events. Why is that?

    Edit: I did set the setAcceptHoverEvents(true) in my constructor.

    1 Reply Last reply
    0
    • B Offline
      B Offline
      bradenedmunds
      wrote on last edited by
      #2

      The only thing that worked for me was setting the protected function to virtual:

      @protected:
      //hover events
      virtual void hoverEnterEvent(QGraphicsSceneHoverEvent *event);
      virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent *event);
      virtual void hoverMoveEvent(QGraphicsSceneHoverEvent *event);@

      1 Reply Last reply
      0
      • G Offline
        G Offline
        Guigui
        wrote on last edited by
        #3

        Thank you for your anwser. Unfortunately, they already are since I always declare overriden functions as virtual for documentation purposes, although it's not strictly necessary. It still doesn't work...

        1 Reply Last reply
        0
        • B Offline
          B Offline
          bradenedmunds
          wrote on last edited by
          #4

          The only other thing I can think of would be setting a flag. For my objects I have:
          @
          setFlags(QGraphicsItem::ItemIsMovable | QGraphicsItem::ItemSendsScenePositionChanges | QGraphicsItem::ItemIsSelectable | QGraphicsItem::ItemSendsGeometryChanges);
          setAcceptHoverEvents(true);
          @

          But I wouldn't think that any of those enable hovering.

          1 Reply Last reply
          0
          • raven-worxR Offline
            raven-worxR Offline
            raven-worx
            Moderators
            wrote on last edited by
            #5

            are you sure you are not filtering the events to the graphics-view's viewport?

            --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
            If you have a question please use the forum so others can benefit from the solution in the future

            1 Reply Last reply
            0
            • G Offline
              G Offline
              Guigui
              wrote on last edited by
              #6

              I honestly don't know how to? What should I look for?

              1 Reply Last reply
              0
              • G Offline
                G Offline
                Guigui
                wrote on last edited by
                #7

                I just noticed that the boundingRect() and shape() functions are not implemented for my NodeItem class. Could it cause a problem in the hovering zone detection?

                1 Reply Last reply
                0
                • B Offline
                  B Offline
                  bradenedmunds
                  wrote on last edited by
                  #8

                  Yes. Qt uses the boundingRect() function to pass events to objects, based on their location.

                  1 Reply Last reply
                  0
                  • G Offline
                    G Offline
                    Guigui
                    wrote on last edited by
                    #9

                    Just tried it. It did not work :(
                    It still only works when I click on the item.

                    1 Reply Last reply
                    0
                    • B Offline
                      B Offline
                      bradenedmunds
                      wrote on last edited by
                      #10

                      Hmm. I would say look at the colliding mice example (Qt\Version\examples\graphicsview\collidingmice), and see if you can implement something close to that. The colliding mice example doesn't currently have hover events, but you could implement them.

                      1 Reply Last reply
                      0
                      • G Offline
                        G Offline
                        Guigui
                        wrote on last edited by
                        #11

                        Tried it... and it works perfectly for the mice! I am clueless about what I am doing wrong here.

                        Could the fact that my NodeItem subclasses the QGraphicsProxyWidget class instead of QGraphicsItem cause a problem? The NodeItem is also composed of a few child QWidgets and QGraphicsItem.

                        EDIT: I also subclass the QGraphicsView and QGraphicsScene classes to implement custom behavior. Should I do anything with the event()/eventFilter() functions?

                        MORE EDITS: Don't think the event()/eventFilter() functions have anything to do with it, as I just ran some experiments on the more complex Diagramscene example and it works! :'(

                        1 Reply Last reply
                        0
                        • G Offline
                          G Offline
                          Guigui
                          wrote on last edited by
                          #12

                          Urrggghhhh! Found it. Problem was event propagation from the GraphicsView.

                          The line
                          @QGraphicsView::mouseMoveEvent(mouseEvent);@

                          was at the wrong place.

                          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