如何在 QML 中设置鼠标光标位置 [英] How to set mouse cursor position in QML

查看:226
本文介绍了如何在 QML 中设置鼠标光标位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 QQuickFrameBufferObject 在 QML 应用程序中渲染 3D 对象.在应用程序中,当我旋转或平移显示的对象时,我希望鼠标光标在 QQuickFrameBufferObject 表面上扭曲.

I am using a QQuickFrameBufferObject to render 3D objects in a QML app. From the app, I would like for the mouse cursor to warp on the QQuickFrameBufferObject surface when I am rotating or translating the objects displayed.

旋转和平移效果很好,但我找不到控制鼠标位置的方法.

Rotation and translation works great, but I can't find a way to control the mouse position.

编辑以更好地解释我所说的翘曲:我所说的翘曲鼠标光标是指当您在屏幕上旋转 3D 对象时,您点击 &拖动鼠标.但是当您到达右侧屏幕的末尾时,您不能再向右拖动,您必须松开鼠标按钮,将鼠标向左移动,单击 &再次拖动以继续旋转.

Edited for better explanation on what I meant by warping : What I mean by warping the mouse cursor is that when you are rotating a 3D object on the screen, you click & drag the mouse. But when you reach the end of the screen on the right, you can no longer drag to the right and you have to release the mouse button, move your mouse to the left, click & drag again to continue your rotation.

我想要做的是传送(或扭曲)鼠标光标到我的渲染表面的左侧,当我拖动并到达右手时渲染表面的一侧,允许我旋转时无限移动

What I want to do is teleport (or warp) the mouse cursor to the left hand side of my rendering surface when I am dragging and I reach the right hand side of the rendering surface, allowing for infinite movement when I rotate

有没有办法让我达到这种效果(可以简单地通过在鼠标到达边界时从 JS 脚本或 C++ 后端设置位置,或者通过有一种方法抓取鼠标并检索相对位置,这可以在某些窗口库中完成).

Is there a way for me to achieve this effect (could be simply by setting the position from a JS script or from the C++ backend when the mouse reaches the border or by having a way to grab the mouse and retrieve the relative positions as can be done in some window libraries).

推荐答案

我不完全了解您的需求,但可能是 QCursor-class 帮助你.

I don't exactly understand your needs, but maybe the QCursor-class helps you.

您可以集成它,例如像这样:

You can integrate it e.g. like this:

#include <QObject>
#include <QCursor>

class MyObj : public QObject
{
    Q_OBJECT
public:
    explicit MyObj(QObject *parent = 0) : QObject(parent)
    {

    }

signals:

public slots:
    void moveCursor() { cursor.setPos(0, 0); } // Sets it to the top left corner of the screen

private:
    QCursor cursor;
};

将其注册到 QML 并在那里使用:

register it to QML and use it there:

ApplicationWindow {
    id: rootWin
    width: 800; height: 600; visible: true

    MyObj {
        id: mob

    }

    Button {
        anchors.centerIn: parent
        onClicked: mob.moveCursor()
    }
}

因此,据我所知,缺少的是如何计算您想要将鼠标移动到的位置(它们是屏幕而不是窗口坐标,所以 mapToGlobal)以及如何触发它,但我猜你最清楚.

So from what I understand what is missing is, how to calculate the position to which you want to move the mouse (they are screen not windows coordinates, so mapToGlobal) and how to trigger it, but that you know best, I guess.

这篇关于如何在 QML 中设置鼠标光标位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆