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. Help with progressbar
Forum Update on Monday, May 27th 2025

Help with progressbar

Scheduled Pinned Locked Moved Solved General and Desktop
progress bar
6 Posts 2 Posters 1.6k 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.
  • J Offline
    J Offline
    Jedd
    wrote on 4 May 2017, 18:06 last edited by Jedd 5 Apr 2017, 18:17
    #1

    I'm having trouble getting a progressbar to work in a dialog. It never triggers, doesn't move. However, I can take this code and plop it into mainwiindow.cpp and it works as expected.

    Edit: if I click the mainwindow's titlebar then click the dialog's titlebar the bar moves a bit, but only when I do the clicks...???

     ui->progressBar->setHidden(false);
     ui->progressBar->setValue(0);
    
    QTimer *timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(usbTimerEvent()));
    timer->start(2000);
    
    
    
      void usbfileDialog::usbTimerEvent()
         {
             int value = ui->progressBar->value()
             if (value >= 100)
              {
                    value = 0;
                    ui->progressBar->reset();
              }   
             ui->progressBar->setValue(value+1);
       }
    
    N 1 Reply Last reply 4 May 2017, 20:21
    0
    • J Jedd
      4 May 2017, 18:06

      I'm having trouble getting a progressbar to work in a dialog. It never triggers, doesn't move. However, I can take this code and plop it into mainwiindow.cpp and it works as expected.

      Edit: if I click the mainwindow's titlebar then click the dialog's titlebar the bar moves a bit, but only when I do the clicks...???

       ui->progressBar->setHidden(false);
       ui->progressBar->setValue(0);
      
      QTimer *timer = new QTimer(this);
      connect(timer, SIGNAL(timeout()), this, SLOT(usbTimerEvent()));
      timer->start(2000);
      
      
      
        void usbfileDialog::usbTimerEvent()
           {
               int value = ui->progressBar->value()
               if (value >= 100)
                {
                      value = 0;
                      ui->progressBar->reset();
                }   
               ui->progressBar->setValue(value+1);
         }
      
      N Offline
      N Offline
      Ni.Sumi
      wrote on 4 May 2017, 20:21 last edited by
      #2

      @Jedd
      I have tired your code. Seems there is no error in the provided code and its works. Where is the Dialog and how you implemented the Dialog in to Mainwindow ?
      This is the code , I have tested.

      MainWindow::MainWindow(QWidget *parent) :
          QMainWindow(parent),
          ui(new Ui::MainWindow)
      {
          ui->setupUi(this);
          mydialog = new QDialog(this);
          QHBoxLayout *mylayout = new QHBoxLayout(this);
          mylayout->addWidget(ui->progressBar);
          mydialog->setLayout(mylayout);
          mydialog->show();
          ui->progressBar->setHidden(false);
          ui->progressBar->setValue(0);
          QTimer *timer = new QTimer(this);
          qDebug() << connect(timer, SIGNAL(timeout()), this, SLOT(valueChange()));
          timer->start(1000);
      }
      
      MainWindow::~MainWindow()
      {
          delete ui;
      }
      
      void MainWindow::valueChange()
      {
               int value = ui->progressBar->value();
               if (value >= 100)
                {
                      value = 0;
                      ui->progressBar->reset();
                }
               ui->progressBar->setValue(value+1);
         }
      
      1 Reply Last reply
      1
      • J Offline
        J Offline
        Jedd
        wrote on 4 May 2017, 21:05 last edited by
        #3

        For me, the dialog is called via a button press

           void MainWindow::on_fmButton_clicked()
               {
                 fmdialog = new usbfileDialog(this);
                 fmdialog->setModal(false);
                 fmdialog->show();   
             }
        

        The dialog code is below:

                   usbfileDialog::usbfileDialog(QWidget *parent) :
                     QDialog(parent),
                       ui(new Ui::usbfileDialog)
                     {   
                          ui->setupUi(this); 
                              ui->usbprogressBar->setHidden(false);
                              ui->usbprogressBar->setValue(0);
        
                              QTimer *timer = new QTimer(this);
                              connect(timer, SIGNAL(timeout()), this, SLOT(usbTimerEvent()));
                             timer->start(2000);
                    }
        
        
                usbfileDialog::~usbfileDialog()
                  {
                     delete ui;
                  }
        
        N 1 Reply Last reply 5 May 2017, 10:51
        0
        • J Jedd
          4 May 2017, 21:05

          For me, the dialog is called via a button press

             void MainWindow::on_fmButton_clicked()
                 {
                   fmdialog = new usbfileDialog(this);
                   fmdialog->setModal(false);
                   fmdialog->show();   
               }
          

          The dialog code is below:

                     usbfileDialog::usbfileDialog(QWidget *parent) :
                       QDialog(parent),
                         ui(new Ui::usbfileDialog)
                       {   
                            ui->setupUi(this); 
                                ui->usbprogressBar->setHidden(false);
                                ui->usbprogressBar->setValue(0);
          
                                QTimer *timer = new QTimer(this);
                                connect(timer, SIGNAL(timeout()), this, SLOT(usbTimerEvent()));
                               timer->start(2000);
                      }
          
          
                  usbfileDialog::~usbfileDialog()
                    {
                       delete ui;
                    }
          
          N Offline
          N Offline
          Ni.Sumi
          wrote on 5 May 2017, 10:51 last edited by Ni.Sumi 5 May 2017, 10:57
          #4

          @Jedd

          I have attached the copy as you said. I did not see any problem like that. do you have any other widget in it ?

          Link to test

          And by default setModal is false. you don't need to set to false and show() pops up the dialog as modeless.

          Edit:

          may be , you need this qApp->processEvents(); If it is busy in running some other local loop with out an event loop / busy in performing the long operation.

          1 Reply Last reply
          1
          • J Offline
            J Offline
            Jedd
            wrote on 5 May 2017, 17:09 last edited by
            #5

            Thanks for the replies. I'll keep looking into it.

            1 Reply Last reply
            0
            • J Offline
              J Offline
              Jedd
              wrote on 5 May 2017, 19:17 last edited by
              #6

              This is weird, but I had applied a vertical layout to this dialog so it would resize a listbox properly. I removed the layout and the progress bar works properly. So solved, I guess...

              1 Reply Last reply
              0

              1/6

              4 May 2017, 18:06

              • Login

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