C++ 将光标更改为沙漏/等待/忙碌光标并返回 Qt

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13495283/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 17:24:16  来源:igfitidea点击:

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

c++qtcursor

提问by sashoalm

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::finishedsignal.

我生成了一个执行冗长操作的进程,我想给出正在发生的视觉反馈,所以我想将光标更改为忙碌状态,并在收到QProcess::finished信号时将其恢复。

回答by Kamil Klimek

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

Qsiris 解决方案是“小部件范围的”。如果要更改整个应用程序的光标,请使用

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.

注意:正如@Ehsan Khodarahmi 所指出的,在触发下一个 QT 事件或手动调用 QApplication::processEvents() 之前,光标不会改变。

回答by Qsiris

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)

这将光标恢复到正常状态(将其放在 QProcess::finished 的插槽中)

this->setCursor(Qt::ArrowCursor);