Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-19036

IntersectsItemBoundingRect mode doesn't work on QGraphicsRectItem with custom shape

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • 5.1.1
    • 4.7.2, 5.1.0
    • Widgets: GraphicsView
    • None
    • 5ec344cc7796b8708e2ae722f7cd184c56844504

    Description

      When calling QGrahpicsScene::items() with IntersectsItemBoundingRect, items with custom shapes are not selected if the point is outside of the shape. Consider the following code:

      class ZeroShapeItem : public QGraphicsRectItem {
      public:
      	ZeroShapeItem(QRectF r) : QGraphicsRectItem(r) {}
      	QPainterPath shape() const { return QPainterPath(); }
      };
      
      main()
      {
          QGraphicsScene scene;
          scene.addItem(new ZeroShapeItem(QRectF(0, 0, 100, 100)));    
          QList<QGraphicsItem*> items = scene.items(QPointF(10, 10), Qt::IntersectsItemBoundingRect, Qt::AscendingOrder);
      }
      

      The returned items will be empty since the scene still calls contains() after testing for bounding rects intersection (at around line 160 in qgraphicssceneindex.cpp). By default. contains() test for shape intersection. Since the item has an empty shape, it's excluded.

      From the wording of the doucmentation, IntersectsItemBoundingRect should return items whose bounds intersects the requested point regardless of its shape.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            mitch_curtis Mitch Curtis
            stephenju Stephen Chu
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes