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::setSelectionArea seems to ignore custom GraphicsItems in view
Forum Updated to NodeBB v4.3 + New Features

QGraphicsScene::setSelectionArea seems to ignore custom GraphicsItems in view

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 431 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.
  • D Offline
    D Offline
    deleted546
    wrote on last edited by deleted546
    #1

    When I do QGraphicsScene::setSelectionArea, the selection adds the item to the selection (ie. QGraphicsScene::selectedItems shows my custom items) but the selection rectangle doesn't include it. It strictly includes the QGraphicsEllipseItem.

    Before selection. The rectangle is a selection rectangle that updates as the mouse is moved. As the mouse is released, setSelectionArea is called on the the rectangle, and the rectangle disappears.

    Note that the curve on the bottom is selectable, and I will show why. Furthermore, it also ends up "selected".
    SelectionRect.png

    However, this is what happens after selection:
    SelectionRectAfter.png

    As proof of the curve being selected, I had this in my code:

    qDebug() << 1 << CurvesSelected << 2 << scene->selectedItems() << 3 << scene->selectionArea();
    

    And the debugger showed this (line endings added here for readability, since my debugger wraps the text):

    1 QSet(QGraphicsItem(0x2d480ed0, pos=0,0, flags=(ItemIsMovable|ItemIsSelectable)), QGraphicsItem(0x2d480ad0, pos=0,0, flags=(ItemIsMovable|ItemIsSelectable))) 
    2 (QGraphicsItem(0x27ddd8e8, pos=0,0, z=20, flags=(ItemIsSelectable)), QGraphicsItem(0x2d480ed0, pos=0,0, flags=(ItemIsMovable|ItemIsSelectable)), QGraphicsItem(0x2d480ad0, pos=0,0, flags=(ItemIsMovable|ItemIsSelectable))) 
    3 QPainterPath: Element count=5
     -> MoveTo(x=-83, y=-53)
     -> LineTo(x=158, y=-53)
     -> LineTo(x=158, y=326)
     -> LineTo(x=-83, y=326)
     -> LineTo(x=-83, y=-53)
    

    Anything in CurvesSelected is of type Curve. It comes from this code:

    foreach (auto item, scene->selectedItems()) {
        Curve *curve = dynamic_cast<Curve *>(item);
        if (curve) {CurvesSelected.insert(curve);}
    }
    

    The 2 curves in the drawing are the wavy thing at the bottom, and the thing at the with blue circles at its corners. Since both the contents of the QSet are within the scene->selectedItems() (the pointers are 0x2d480ed0 and 0x2d480ad0) which are also in line 2, representing scene->selectedItems().

    My issue is: The rectangle drawn after setSelectionArea was called only covered the QGraphicsEllipseItem. This seems like a bug to me, as it ought to cover all the items in scene->selectedItems(), should it not?

    I can work around this by implementing my own setSelectionArea or something to include all QGraphicsItems, including ones that are custom defined, but it would've been convenient to use Qt's own member function where possible. And if there's a good reason it doesn't work this way, I'd prefer to know it, (and ideally, that detail should be included in the documentation).

    It's worth noting the debugger clearly shows the items as selectable (and also movable, but that's irrelevant right now), so that's not where the bug is.

    1 Reply Last reply
    0
    • D Offline
      D Offline
      deleted546
      wrote on last edited by
      #2

      Moving this to bug reports. Until I do, I'm leaving this unsolved in case anyone wants to respond. Sorry, new to this, so I didn't know.

      mrjjM 1 Reply Last reply
      0
      • D deleted546

        Moving this to bug reports. Until I do, I'm leaving this unsolved in case anyone wants to respond. Sorry, new to this, so I didn't know.

        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3

        @Mad_Maniac
        Hi
        If you post a link to the bug report here, people can vote for this issue.

        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