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. Making a QGraphicsRectItem "transparent" to mouse clicks
Forum Updated to NodeBB v4.3 + New Features

Making a QGraphicsRectItem "transparent" to mouse clicks

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 933 Views 3 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.
  • bleriot13B Offline
    bleriot13B Offline
    bleriot13
    wrote on last edited by bleriot13
    #1

    Hi!

    I'm developing an application where lots of points are show on the screen. These points are clickable, and when this happens, lines connecting these points to other ones ("edges") are shown.

    The user may select (using a rubber band) a rectangular section and start some background process. Once it is over, this area is "special" because it has already been processed. Since I want the user to be aware of what are the areas that have been taken care of, I draw QGraphicsRectItem covering the area that was selected with the rubber band.

    Here come the problems.

    I insert the QGraphicsRectItem using the same z value as the points. The problem is, therefore, that since there are so many (so many!!!) points in the scene, the rectangle is almost invisible, since it is somehow covered by the point items.

    If I use a z value for the rectangles greater than that for the points, then the rectangles are perfectly visible, but... since now they "cover" the points, the clicks over these are somehow captured by the rectangles, so I miss the point selection ability.

    I hope that my problem is clear now. The question, then, is very simple: how can I make the rectangles "transparent" to mouse clicks while using a z value that make them appear nicely drawn on the screen?

    Using QT 5.9. Windows.

    Thanks!

    Edit: I tried calling setAcceptedMouseButtons(0) when creating the rectangle, but this didn't worked.

    Edit 2: I've also overriden the mousePressEvent and mouseReleaseEvent methods. These only ignore the event:

    void
    VEProcessedAreaItem::
    mousePressEvent
    (QGraphicsSceneMouseEvent *event)
    {
      {
        event->ignore();
      }
    }
    
    void
    VEProcessedAreaItem::
    mouseReleaseEvent
    (QGraphicsSceneMouseEvent *event)
    {
      {
        event->ignore();
      }
    }
    

    It didn't worked.

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

      Hi,

      You may find an interesting example in Qt'ssetAcceptedMouseButtons.

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

      1 Reply Last reply
      0
      • bleriot13B Offline
        bleriot13B Offline
        bleriot13
        wrote on last edited by
        #3

        Hi.

        Your answer confirms that this is the right way (using setAcceptedMouseButtons).

        Since I'm already using this method but it does not work, I guess there's something wrong in my code. I'll keep trying.

        Thank you.

        1 Reply Last reply
        0
        • A Offline
          A Offline
          Asperamanca
          wrote on last edited by Asperamanca
          #4

          From the QGraphicsItem docs:

          "The mouse press event decides which item should become the mouse grabber (see QGraphicsScene::mouseGrabberItem()). If you do not reimplement this function, the press event will propagate to any topmost item beneath this item, and no other mouse events will be delivered to this item."

          So there is something fishy going on for sure...

          EDIT: Also, I use items which cover other items all the time. I don't typically have issues what items "catch" the events, unless I have event handlers in there.

          However, consider that certain GraphicsItemFlags can implicitly cause items to accept mouse events (e.g. if the item is moveable, it needs to handle mouse clicks).

          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