简体   繁体   中英

How to change cursor inside slot triggered by signal from QAction

In my application, I do an extensive algorithm immediately after I open a file (using QAction in menubar). I want to change the cursor to busy mode but somehow my code doesn't work:

MyApp::MyApp(QWidget *parent)
    : QMainWindow(parent)
{
    ui.setupUi(this);
    connect(ui.openFileOption, SIGNAL(triggered()), this, SLOT(OpenFileAction()));
}

MyApp::~MyApp()
{
}

void MyApp::OpenFileAction()
{
    //change cursor
    this->setCursor(Qt::WaitCursor);
    QApplication::processEvents();

    // load file

    // do something long here...

    this->setCursor(Qt::ArrowCursor);
}

You can try the following code (provided by Qt documentation, btw):

QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
// load file
// do something long here...
QApplication::restoreOverrideCursor();

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