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. Make QGraphicsItem non interactive with mouse.

Make QGraphicsItem non interactive with mouse.

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 1.1k Views
  • 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.
  • GofferG Offline
    GofferG Offline
    Goffer
    wrote on last edited by Goffer
    #1

    Hello guys,

    I have a QGraphicsView with mouse interaction, mainly a rubberband selection that works just fine. Now I am trying to add a QGraphicsItem(we will name it Box) that will be a container for other QGraphicsItems.

    So basically I need to be able to use my rubberband selection inside this Item (Box) as if I was directly in the scene.
    I've tried to ignore some events (mousePress/Move/Release) inside the item (Box) hopping that it would then use the scene events. but it doesn't work. Ignore will should send towards the parentItem but the view not being a valid parentItem, my item (Box) doesn't have a parent

    I just want my item (Box) to be treated as a background color, the item itself will be controlled via handles being children items.

    How could I achieve this behaviour ?
    Thx :)

    1 Reply Last reply
    0
    • Chris KawaC Online
      Chris KawaC Online
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Don't fiddle with events. Just indicate to the item that it should not receive them in the first place:

      item->setAcceptedMouseButtons(Qt::NoButton);
      
      1 Reply Last reply
      1
      • GofferG Offline
        GofferG Offline
        Goffer
        wrote on last edited by
        #3

        I've tried that too without success

        1 Reply Last reply
        0
        • Chris KawaC Online
          Chris KawaC Online
          Chris Kawa
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Then you're doing something else wrong because that's all it takes. Can you compose a minimal code example of what you're doing?

          1 Reply Last reply
          1
          • GofferG Offline
            GofferG Offline
            Goffer
            wrote on last edited by
            #5

            My bad, I ve found the mistake, when designing the rubberband at the view level, I've added as a condition that there shouldn't be any item bellow the pointer ...

            by commenting it out it works.

            1 Reply Last reply
            0
            • Chris KawaC Online
              Chris KawaC Online
              Chris Kawa
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Just to make sure you're aware - QGraphicsScene has a built-in rubberband support.
              There's no need to implement it manually: view->setDragMode(QGraphicsView::RubberBandDrag).

              1 Reply Last reply
              1
              • GofferG Offline
                GofferG Offline
                Goffer
                wrote on last edited by
                #7

                Yeah I know, I ve re-implemented it because it didn't work 100% for what I'm doing

                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