Change cursor to hourglass/wait/busy cursor and back in Qt

孤街醉人 提交于 2019-12-03 10:29:35

问题


I spawn a process that performs a lengthy operation, and I'd like to give visual feedback that something is happening, so I want to change the cursor to busy and restore it when I receive the QProcess::finished signal.


回答1:


Qsiris solution is "widget wide". If you want to change cursor for your whole application then use

QApplication::setOverrideCursor(Qt::WaitCursor);

and

QApplication::restoreOverrideCursor();

Note: As @Ehsan Khodarahmi pointed out, the cursor will NOT change until triggering next QT event or calling QApplication::processEvents() manually.




回答2:


Use this to set the cursor to wait when the process begins:

this->setCursor(Qt::WaitCursor);

And this to restore the cursor back to normal (put this in the slot for QProcess::finished)

this->setCursor(Qt::ArrowCursor);


来源:https://stackoverflow.com/questions/13495283/change-cursor-to-hourglass-wait-busy-cursor-and-back-in-qt

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!