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. Stop a waiting spinner QWidget using QShortcut
Forum Update on Monday, May 27th 2025

Stop a waiting spinner QWidget using QShortcut

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 305 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.
  • H Offline
    H Offline
    hbatalha
    wrote on last edited by
    #1

    I have been using this QtWaitingSpinner and it works as expected.

    However I want to be able to cancel it any time it is spinning using the Esc key. But using QShortcut does work because once it start spinning it sets my MainWindow disabled.

    My problem is also described in this issue, that had no reply.

    I would appreciate any idea on how to make QShortcut work with QtWaitingSpinner .

    JonBJ 1 Reply Last reply
    0
    • H hbatalha

      I have been using this QtWaitingSpinner and it works as expected.

      However I want to be able to cancel it any time it is spinning using the Esc key. But using QShortcut does work because once it start spinning it sets my MainWindow disabled.

      My problem is also described in this issue, that had no reply.

      I would appreciate any idea on how to make QShortcut work with QtWaitingSpinner .

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @hbatalha
      I read through the QtWaitingSpinner. You say

      But using QShortcut does work because once it start spinning it sets my MainWindow disabled.

      But (I read it as) that is only an option:

      As an alternative example, the code below will create a spinner that (1) blocks all user input to the main application for as long as the spinner is active, (2) automatically centres itself on its parent widget every time "start" is called and (3) makes use of the default shape, size and colour settings.

      	QtWaitingSpinner* spinner = new QtWaitingSpinner(this, Qt::ApplicationModal, true);
      
      	spinner->start(); // starts spinning
      

      and you yourself said

      This is only possible if I set ' disableParentWhenSpinning=false'.

      You are passing the constructor false for this, aren't you?

      H 1 Reply Last reply
      1
      • JonBJ JonB

        @hbatalha
        I read through the QtWaitingSpinner. You say

        But using QShortcut does work because once it start spinning it sets my MainWindow disabled.

        But (I read it as) that is only an option:

        As an alternative example, the code below will create a spinner that (1) blocks all user input to the main application for as long as the spinner is active, (2) automatically centres itself on its parent widget every time "start" is called and (3) makes use of the default shape, size and colour settings.

        	QtWaitingSpinner* spinner = new QtWaitingSpinner(this, Qt::ApplicationModal, true);
        
        	spinner->start(); // starts spinning
        

        and you yourself said

        This is only possible if I set ' disableParentWhenSpinning=false'.

        You are passing the constructor false for this, aren't you?

        H Offline
        H Offline
        hbatalha
        wrote on last edited by
        #3

        @JonB

        I read through the QtWaitingSpinner. You say

        But using QShortcut does work because once it start spinning it sets my MainWindow disabled.

        Actually there's a missing not in that statement. It does not work.

        You are passing the constructor false for this, aren't you?

        No, I forgot to mention that I need the MainWindow to be disabled or simply disable all its widgets.
        If I pass false then the user can navigate the MainWindow, behavior that I want to avoid. And if I pass true QShortcut does not work.

        A plan B solution I just thought right now is to disable everything in the MainWindow, toolbar, menubar, they are not that many. It's an ugly solution though.

        1 Reply Last reply
        0
        • H Offline
          H Offline
          hbatalha
          wrote on last edited by
          #4

          I came up with a solution that turned out not to be as ugly as I first pictured it
          I replied the answer to that issue

          For new comers: I came up with a solution that works for me.

          First I used the fork from https://github.com/huxingyi/QtWaitingSpinner (found in the PR in this repo), that allowed me to use text. Note that it uses an obsolete (I am using Qt 6.1.2) method, I fixed that and you can find the fix in a PR I opened there.

          Now when using:

          I set disableParentWhenSpinning to false when calling the ctor, that way it permits me to use QShortcut in the MainWindow and then went to disable all the widgets I had present in my MainWindow.

          
          MainWindow::MainWindow()
          
             : QMainWindow(0)
          
             , ui(new Ui::MainWindow)
          
          {
          
          ...
          
             spinner = new WaitingSpinnerWidget(this, Qt::ApplicationModal, false);
          
             spinner->setText(tr("Press Esc to cancel"));
          
             spinner->setTextColor(Qt::black);
          
          
          
             QShortcut* sh = new QShortcut(QKeySequence(Qt::Key_Escape), this);
          
             connect(sh, &QShortcut::activated, this, [this] { setSpinner(false); }); // you might check if `spinner` is running before calling the function setSpinner
          
          
          
          ...
          
          }
          
          
          
          void MainWindow::setSpinner(bool enabled)
          
          {
          
             if(enabled)
          
                 spinner->start();
          
             else
          
                 spinner->stop();
          
          
          
             menuBar()->setDisabled(enabled);
          
             ui->toolBar->setDisabled(enabled);
          
             ui->tableWidget->setDisabled(enabled);
          
          }
          
          
          1 Reply Last reply
          0

          • Login

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