matlab游标标注移动,MATLAB将鼠标光标移动到特定坐标

坐标系似乎如下:x = 0,y = 0是主监视器的左上角.正X从左向右移动.正Y从上到下移动. (非常典型)

(顺便说一下,你应该使用screenSizes = get(0,’MonitorPositions’)而不是screenize,因为它可以正确处理多个监视器.)

以下命令对我有用:

%Setup

robot = java.awt.Robot;

screenSizes = get(0, 'MonitorPositions');

%Mouse to upper left of primary monitor

robot.mouseMove(1, 1)

%Mouse to center of primary monitor

robot.mouseMove(mean(screenSizes(1,[1 3])),mean(screenSizes(1,[2 4])))

%Mouse to hardcoded point 200 pixels down and 500 pixels to the right

robot.mouseMove(500, 200)

%Slow horizontal drag

for ix = 1:500

robot.mouseMove(ix, 200);

pause(0.01)

end

顺便提一下,您发布的代码似乎对我有用,将鼠标从左上角向右下角移动.所以很遗憾,上面的代码(对我有用)可能会遇到你原来遇到的问题. FWIW,我的版本信息是:

MATLAB Version 7.12.0.635 (R2011a)

Operating System: Microsoft Windows XP Version 5.1 (Build 2600: Service Pack 3)

Java VM Version: Java 1.6.0_31-b05 with Sun Microsystems Inc. Java HotSpot(TM) Client VM mixed mode

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
如果你正在使用 QwtPlot 库,可以通过以下步骤实现游标移动: 1. 创建一个 QwtPlotMarker 对象来表示游标。 2. 将游标添加到 QwtPlot 中。使用 QwtPlot::insertMarker() 或 QwtPlot::addMarker() 方法来添加游标。 3. 捕获鼠标移动事件,并在事件处理程序中更新游标位置。 以下是示例代码: ```cpp // 创建游标对象 QwtPlotMarker *cursor = new QwtPlotMarker(); cursor->setLineStyle(QwtPlotMarker::VLine); cursor->setLinePen(Qt::black); cursor->setXValue(0.0); // 初始位置 // 将游标添加到 QwtPlot cursor->attach(qwtPlot); // 捕获鼠标移动事件 qwtPlot->canvas()->installEventFilter(this); // 处理鼠标移动事件 bool MyWidget::eventFilter(QObject *obj, QEvent *event) { if (event->type() == QEvent::MouseMove && obj == qwtPlot->canvas()) { QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event); // 将鼠标位置转换为坐标系值 double x = qwtPlot->invTransform(QwtPlot::xBottom, mouseEvent->pos().x()); double y = qwtPlot->invTransform(QwtPlot::yLeft, mouseEvent->pos().y()); // 更新游标位置 cursor->setXValue(x); cursor->setYValue(y); // 重新绘制 QwtPlot qwtPlot->replot(); } return false; } ``` 这段代码创建了一个垂直线样式的游标对象,并将其添加到 QwtPlot 中。然后,它捕获 QwtPlot 的鼠标移动事件,并在事件处理程序中更新游标位置。请注意,这里使用了 QwtPlot::invTransform() 方法将鼠标位置转换为坐标系值。最后,调用 QwtPlot::replot() 方法重新绘制 QwtPlot。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值