简体   繁体   中英

Cursor won't change for my QGraphicsView

I have created my own widget based on 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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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