QT:绘制跟随光标的图元

QT: Drawing Primitves to Follow Cursor

本文关键字:图元 光标 跟随 绘制 QT      更新时间:2023-10-16

我对QT有点陌生。我有一个单独的Crosshair类,它只是使用QPainterQPen来渲染十字线。我使用了paint()函数,它确实在窗口的某个位置显示了十字光标。如何使十字光标跟随当前鼠标位置?

这是我的方法,但我无法让它发挥作用。我在学习VoidRealms教程。

void Crosshair::mouseMoveEvent(QGraphicsSceneMouseEvent *event){
   // i want to update the x and y position when the mouse moves
   //x = mouse.x
   //y = mouse.y
   QGraphicsItem::mouseMoveEvent(event);
   update();
 }

这应该为您完成:

this->setPos(event->x(), event->y());

如果在QGraphicsSceneMouseEvent之外进行场景映射,还可以使用其他辅助功能。

我在这里描述过:

如何在QGraphicsScene上绘制点(单击鼠标)?

希望能有所帮助。