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

Interaction between DeviceCoordinateCache and QGraphicsDropShadowEffect causing QGraphicsItems to be cropped

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 5.12.2
    • Widgets: GraphicsView
    • None
    • I've seen this bug on Ubuntu and Debian, probably with separate Qt versions.
    • Linux/X11

    Description

      When a QGraphicsItem has the following properties, it gets incorrectly cropped:

      1. Uses a QGraphicsItem::DeviceCoordinateCache cache mode
      2. has a QGraphicsDropShadowEffect
      3. is bigger than the viewport.

      The following short program reproduces the issue. There are two graphics items, a red and blue square of the same size and in the same position. The blue square should be completely hidden by the red square, but that's not what happens. Instead, the blue square is visible because the red square is getting cropped by this bug. See attached image. If either the cache mode or the drop shadow are removed from the red square, the issue goes away.

      #include <QWidget>
      #include <QFrame>
      #include <QApplication>
      #include <QGraphicsScene>
      #include <QGraphicsView>
      #include <QGraphicsItem>
      #include <QPainter>
      #include <QtWidgets/QGraphicsEffect>
      
      #include <memory>
      
      struct TestItem : QGraphicsItem
      {
        TestItem(QColor c, bool dropShadow) : m_rect(4, 4, 604, 604), m_color(c)
        {
          setCacheMode(QGraphicsItem::DeviceCoordinateCache);
          if (dropShadow)
          {
            setGraphicsEffect(new QGraphicsDropShadowEffect);
          } 
        }
      
        QRectF boundingRect() const override { return m_rect; }
      
        void paint(QPainter *painter, const QStyleOptionGraphicsItem*, QWidget*) override
        {
            painter->fillRect(m_rect, m_color);
        }
      
        QRect m_rect;
        QColor m_color;
      };
      
      int main(int argc, char** argv)
      {
        QApplication app(argc, argv);
        std::unique_ptr<QFrame> frame( new QFrame());
        frame->resize(500, 500);
      
        QGraphicsScene* scene(new QGraphicsScene(-1000, -1000, 1000, 1000, frame.get()));
        QGraphicsView* view(new QGraphicsView(scene, frame.get()));
      
        view->setMinimumSize(QSize(500, 500));
        view->setMaximumSize(QSize(500, 500));
        view->setSceneRect(200, 200, 700, 700);
        view->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
        view->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
      
        scene->addItem(new TestItem(Qt::blue, false));
        scene->addItem(new TestItem(Qt::red, true));
      
        frame->show();
        return app.exec();
      }
      

      Attachments

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

        Activity

          People

            bibr Andreas Aardal Hanssen
            malcohol Malcolm Tyrrell
            Votes:
            3 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes