show message when setting SetOverrideCursor()
-
I have the following code, a message is displayed when setting setOverrideCursor (), my problem is that the message box does not close in the time indicated in singleShot (), I have to click on the button to close it.
my question is how can I make the message box close automatically.void Widget::on_pushButton_4_clicked() { QGuiApplication::setOverrideCursor(Qt::WaitCursor); QMessageBox* box=new QMessageBox; box->setText("Creating the backup, please wait."); box->setWindowTitle(qApp->applicationName()); box->setIcon(QMessageBox::Information); box->setAttribute(Qt::WA_DeleteOnClose); box->exec(); QTimer::singleShot(1000,this,&QGuiApplication::restoreOverrideCursor); } -
Hello!
Your code works but need just some adjustments. Please check out my code and the screenshot below:
void Widget::on_pushButton_4_clicked() { QApplication::setOverrideCursor(Qt::WaitCursor); QMessageBox *box = new QMessageBox(this); box->setText("Creating the backup, please wait."); box->setWindowTitle(qApp->applicationName()); box->setIcon(QMessageBox::Information); box->setAttribute(Qt::WA_DeleteOnClose); QTimer::singleShot(1000, this, [box, this]() { box->close(); box->deleteLater(); QApplication::restoreOverrideCursor(); }); box->exec(); }Result:

In the lambda
QTimer::singleShotyou can close your message box. Also, keep in mind thatboxis a pointer and you always must calldeleteLater()method. Happy coding! -
Hello!
Your code works but need just some adjustments. Please check out my code and the screenshot below:
void Widget::on_pushButton_4_clicked() { QApplication::setOverrideCursor(Qt::WaitCursor); QMessageBox *box = new QMessageBox(this); box->setText("Creating the backup, please wait."); box->setWindowTitle(qApp->applicationName()); box->setIcon(QMessageBox::Information); box->setAttribute(Qt::WA_DeleteOnClose); QTimer::singleShot(1000, this, [box, this]() { box->close(); box->deleteLater(); QApplication::restoreOverrideCursor(); }); box->exec(); }Result:

In the lambda
QTimer::singleShotyou can close your message box. Also, keep in mind thatboxis a pointer and you always must calldeleteLater()method. Happy coding!@Cobra91151
great man, thanks for your answer, I was able to solve my problem already.
thanks again.