#include #include #include #include #include int main(int argc, char* argv[]) { QApplication app(argc, argv); QGraphicsScene scene; for (int i = 0; i< 25; i++) { QPointF pos(75000 + qrand()%1000, 125000 + qrand()%750); QGraphicsRectItem* rect = scene.addRect(QRect(-5, -5, 10, 10), QPen(Qt::blue), Qt::white); rect->setPos(pos); rect->setFlag(QGraphicsRectItem::ItemIgnoresTransformations); rect->setFlag(QGraphicsRectItem::ItemIsSelectable); // The following line is a workaround for the problem //rect->mapToScene(QPointF(0, 0)); } // The following line is a workaround for the problem //scene.setSceneRect(scene.sceneRect()); QGraphicsView view(&scene); view.setDragMode(QGraphicsView::RubberBandDrag); view.show(); QObject::connect(&scene, &QGraphicsScene::sceneRectChanged, [=](const QRectF& newRect) {qDebug() << newRect; }); return app.exec(); }