Details
-
Bug
-
Resolution: Unresolved
-
P2: Important
-
None
-
5.12.2
-
None
-
I've seen this bug on Ubuntu and Debian, probably with separate Qt versions.
Description
When a QGraphicsItem has the following properties, it gets incorrectly cropped:
- Uses a QGraphicsItem::DeviceCoordinateCache cache mode
- has a QGraphicsDropShadowEffect
- 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(); }