简体   繁体   English

我的QGraphicsView的光标不会改变

[英]Cursor won't change for my QGraphicsView

I have created my own widget based on QGraphicsView. 我已经基于QGraphicsView创建了自己的小部件。 I did this in order to re-implement some mouse events as such: 我这样做是为了重新实现一些鼠标事件,例如:

void Workspace::mouseMoveEvent(QMouseEvent *event)
{
    qDebug() << (QString("Mouse move (%1,%2)").arg(event->x()).arg(event->y()));

    QGraphicsView::mouseMoveEvent(event); 
}

as well as install an event filter 以及安装事件过滤器

bool Workspace::eventFilter(QObject* obj, QEvent* e)
{
    if(e->type() == QEvent::Enter)
        qDebug() << "Entered Workspace";
}

I did not liked the default 'hand' mouse pointer though and I decided to change it using 我不喜欢默认的“手”鼠标指针,因此决定使用

this->setCursor(Qt::CrossCursor);

in my constructor. 在我的构造函数中。

What happens though is the mouse pointer changing into a cross only while being at the very first pixel of the widget. 但是,发生的情况是鼠标指针仅在小部件的第一个像素处才变成十字形。 The moment I move further in it goes back to the default 'hand' cursor that is used to signify drag functionality. 当我进一步移动时,它会返回到默认的“手”光标,该光标用于表示拖动功能。

Why is this happening and how can I change the cursor to whatever I like? 为什么会发生这种情况,如何将光标更改为自己喜欢的位置?

It seems that using 似乎使用

QApplication::setOverrideCursor(Qt::CrossCursor);

when entering the widget, and 输入小部件时,以及

QApplication::restoreOverrideCursor();

when exiting, does the trick. 退出时,把戏。

I am not sure why setCursor did not work though. 我不确定为什么setCursor无法正常工作。

EDIT 编辑

Actually using the above is not such a good idea, as it is simpler to just use 实际上使用上面的方法不是一个好主意,因为使用起来更简单

QApplication::changeOverrideCursor(*mCurrentCursor);

you will not have to worry about anything else this way, Qt will take care of stack en-queue/de-queue. 这样您就不必担心其他任何事情,Qt会处理堆栈入队/出队。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM