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. QGraphicsScene hover*Events to all item under mouse cursor.
Forum Updated to NodeBB v4.3 + New Features

QGraphicsScene hover*Events to all item under mouse cursor.

Scheduled Pinned Locked Moved Solved General and Desktop
13 Posts 2 Posters 862 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.
  • ABDUA Offline
    ABDUA Offline
    ABDU
    wrote on last edited by ABDU
    #1

    Hello!
    I am making an application that is similar to the Diagram Scene Example. I expanded it by adding a resizer item(SizeGripItem) and in the future, I want to add a slightly similar element in the structure. And they all use hover*Events.
    The problem is that both of these items(SizeGripItem and another "future item") are child of the DiagramItem, and they lie on top of the parent. So all hover*Events are received by the element that was added last. In fact, they all get it, but in the wrong way. For example, hoverMoveEvent works only once when it enters the child's shape. Which is not typical for this event. I tried this option from the StackOverflow post. It says that you need to redefine QGraphicsView or QGraphicsScene mouseMoveEvent and send events using QGraphicsScene::sendEvent, but it seems to me that this is a bit of a crutch way. Because as I understood it, I would have to implement the full logic of all hover events from scratch. I also tried to call event->ignore(), but the documentation says that this has no effect.

    The looks of the DiagramItem with SizeGripItem and "future item" when it's hovered.
    Screen Shot 07-22-21 at 11.07 PM.PNG

    The looks of the DiagramItem with SizeGripItem and "future item" when it's
    not hovered.

    Screen Shot 07-22-21 at 11.31 PM.PNG

    Thanks for any help or suggestions that will help solve this problem.

    1 Reply Last reply
    0
    • ABDUA Offline
      ABDUA Offline
      ABDU
      wrote on last edited by
      #13

      @SGaist
      Out of curiosity, why are you making three different items for what seems to be only one in the end ?

      I realized that my mistake was that I was creating separate elements when only one is created in the end. Having redone this, everything worked as it should. Thank you!

      1 Reply Last reply
      1
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi and welcome to devnet,

        What about reverting the order of the items ?

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        ABDUA 1 Reply Last reply
        0
        • SGaistS SGaist

          Hi and welcome to devnet,

          What about reverting the order of the items ?

          ABDUA Offline
          ABDUA Offline
          ABDU
          wrote on last edited by
          #3

          @SGaist Please excuse me if I misunderstand something. But as I understand it, you want me to make children as the parent of the DiagramItem? That is:

          From this:
          DiagramItem
          |_SizeGripItem
          |_"future item"

          To this:
          SizeGripItem
          |_DiagramItem

          "future item"
          |_DiagramItem

          But is that really to have more than one parent? Sorry for not showing the hierarchy initially.

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #4

            I meant to stack them differently, so future on top of size grip on top of main item.

            Are you grouping them ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            ABDUA 2 Replies Last reply
            0
            • SGaistS SGaist

              I meant to stack them differently, so future on top of size grip on top of main item.

              Are you grouping them ?

              ABDUA Offline
              ABDUA Offline
              ABDU
              wrote on last edited by
              #5
              This post is deleted!
              1 Reply Last reply
              0
              • SGaistS SGaist

                I meant to stack them differently, so future on top of size grip on top of main item.

                Are you grouping them ?

                ABDUA Offline
                ABDUA Offline
                ABDU
                wrote on last edited by
                #6

                @SGaist No, I'm not grouping them, just parenting. Here is the code of how item is created. ArrowManager is "future item". Just temporary name.

                DiagramItem *DiagramScene::createDiagramItem(int diagramType)
                {
                    DiagramItem* diagramItem = new DiagramItem(DiagramItem::DiagramType(diagramType));
                
                    SizeGripItem* sizeGripItem =
                            new SizeGripItem(new PathResizer, diagramItem);
                
                    new ArrowManager(diagramItem);
                
                    connect(sizeGripItem, &SizeGripItem::resizeBeenMade,
                            diagramItem,  &DiagramItem::updateTextItemPosition);
                
                    connect(diagramItem, &DiagramItem::itemPositionChanged,
                            this,        &DiagramScene::drawLevelLineWithItemOnSameAxis);
                
                    connect(diagramItem, &DiagramItem::itemReleased,
                            this,        &DiagramScene::deleteAllLevelLines);
                
                    return diagramItem;
                }
                
                1 Reply Last reply
                0
                • SGaistS Offline
                  SGaistS Offline
                  SGaist
                  Lifetime Qt Champion
                  wrote on last edited by
                  #7

                  Out of curiosity, why are you making three different items for what seems to be only one in the end ?

                  Interested in AI ? www.idiap.ch
                  Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                  ABDUA 1 Reply Last reply
                  1
                  • SGaistS SGaist

                    Out of curiosity, why are you making three different items for what seems to be only one in the end ?

                    ABDUA Offline
                    ABDUA Offline
                    ABDU
                    wrote on last edited by
                    #8

                    @SGaist It seemed to me that this is the easiest and most convenient option, that is, to manage everything separately. Yes, maybe this is not the best option, but due to my inexperience, nothing better comes to my mind except this option.

                    1 Reply Last reply
                    0
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #9

                      Can you share a minimal compilable example ?

                      That will allow to better understand your implementation and what is happening.

                      Interested in AI ? www.idiap.ch
                      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                      ABDUA 1 Reply Last reply
                      0
                      • SGaistS SGaist

                        Can you share a minimal compilable example ?

                        That will allow to better understand your implementation and what is happening.

                        ABDUA Offline
                        ABDUA Offline
                        ABDU
                        wrote on last edited by
                        #10

                        @SGaist Of course, but it will take some time. How is it convenient for you to provide the code? Should I leave the pieces of code here in this way:

                        DiagramItem.h

                        // DiagramItem definition code
                        // ...
                        

                        DiagramItem.cpp

                        // DiagramItem implementation code
                        // ...
                        

                        etc

                        // ...
                        

                        or in some other way?

                        Thank you so much for your support!

                        1 Reply Last reply
                        0
                        • SGaistS Offline
                          SGaistS Offline
                          SGaist
                          Lifetime Qt Champion
                          wrote on last edited by
                          #11

                          Either that or if you have a GitLab/GitHub/BitBucket/Other repo.

                          Interested in AI ? www.idiap.ch
                          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                          ABDUA 1 Reply Last reply
                          0
                          • SGaistS SGaist

                            Either that or if you have a GitLab/GitHub/BitBucket/Other repo.

                            ABDUA Offline
                            ABDUA Offline
                            ABDU
                            wrote on last edited by
                            #12

                            @SGaist Here is a minimal example. I don't know if the example is small enough. But I tried to make it as small as possible.

                            1 Reply Last reply
                            0
                            • ABDUA Offline
                              ABDUA Offline
                              ABDU
                              wrote on last edited by
                              #13

                              @SGaist
                              Out of curiosity, why are you making three different items for what seems to be only one in the end ?

                              I realized that my mistake was that I was creating separate elements when only one is created in the end. Having redone this, everything worked as it should. Thank you!

                              1 Reply Last reply
                              1

                              • Login

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