[SOLVED] Qt – change cursor to hourglass and disable cursor


Currently I am working on a Qt program. To prevent the user from interacting with the application when a long task is running, I tried overriding the cursor by calling


However, mouse click events aren’t disabled.

Is there any way to disable mouse click events without disabling all widgets of GUI?


I spent a lot of time to find a way to actually prevent user interaction in Qt and it occurs that event filtering seems to be an acceptable solution.

Here an example:

class AppFilter : public QObject
    bool eventFilter( QObject *obj, QEvent *event );

bool AppFilter::eventFilter(QObject *obj, QEvent *event)
    switch ( event->type())
    //list event you want to prevent here ...
    case QEvent::KeyPress:
    case QEvent::KeyRelease:
    case QEvent::MouseButtonRelease:
    case QEvent::MouseButtonPress:
    case QEvent::MouseButtonDblClick:
    return true;
    return QObject::eventFilter( obj, event );

Then when you what to lock:


And unlock:

while( qapp->overrideCursor()) //be careful application may have been lock several times ...

Answered By – Thomas Vincent

Answer Checked By – Katrina (BugsFixing Volunteer)

Leave a Reply

Your email address will not be published. Required fields are marked *