This works fine for me
class MyQGraphicsItem : public QGraphicsItem
{
public:
using QGraphicsItem::QGraphicsItem;
QRectF boundingRect() const override { return QRectF(0, 0, 50, 50); }
void paint(QPainter* painter, const QStyleOptionGraphicsItem* option, QWidget* widget = nullptr) override
{
painter->fillRect(boundingRect(), Qt::red);
}
};
class MyQGraphicsView : public QGraphicsView
{
public:
using QGraphicsView::QGraphicsView;
void mousePressEvent(QMouseEvent *event) override
{
delete moveEvent;
moveEvent = new QMouseEvent(event->type(), event->localPos(), event->globalPos(), event->button(), event->buttons(), event->modifiers());
qDebug() << event;
QTimer::singleShot(1000, this, &MyQGraphicsView::doSomething);
}
void doSomething()
{
qDebug() << moveEvent;
}
QMouseEvent* moveEvent = nullptr;
};
int main(int argc, char* argv[])
{
QApplication app(argc, argv);
QGraphicsScene scene;
scene.addItem(new MyQGraphicsItem);
MyQGraphicsView view(&scene);
view.show();
return app.exec();
}
--> same local & global pos even after 1 second timer.