Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. show message when setting SetOverrideCursor()
Qt 6.11 is out! See what's new in the release blog

show message when setting SetOverrideCursor()

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 643 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • lincolnL Offline
    lincolnL Offline
    lincoln
    wrote on last edited by lincoln
    #1

    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);
    }
    
    

    Solitary wolf

    1 Reply Last reply
    0
    • Cobra91151C Offline
      Cobra91151C Offline
      Cobra91151
      wrote on last edited by Cobra91151
      #2

      @lincoln

      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:
      QMessageBox_on_timer_example.gif

      In the lambda QTimer::singleShot you can close your message box. Also, keep in mind that box is a pointer and you always must call deleteLater() method. Happy coding!

      lincolnL 1 Reply Last reply
      1
      • Cobra91151C Cobra91151

        @lincoln

        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:
        QMessageBox_on_timer_example.gif

        In the lambda QTimer::singleShot you can close your message box. Also, keep in mind that box is a pointer and you always must call deleteLater() method. Happy coding!

        lincolnL Offline
        lincolnL Offline
        lincoln
        wrote on last edited by
        #3

        @Cobra91151
        great man, thanks for your answer, I was able to solve my problem already.
        thanks again.

        Solitary wolf

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved