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
Qt 6.11 is out! See what's new in the release blog

Help with progressbar

Scheduled Pinned Locked Moved Solved General and Desktop
progress bar
6 Posts 2 Posters 2.2k Views 1 Watching
  • 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 last edited by Jedd
    #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);
       }
    
    Ni.SumiN 1 Reply Last reply
    0
    • J Jedd

      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);
         }
      
      Ni.SumiN Offline
      Ni.SumiN Offline
      Ni.Sumi
      wrote on 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 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;
                  }
        
        Ni.SumiN 1 Reply Last reply
        0
        • J Jedd

          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;
                    }
          
          Ni.SumiN Offline
          Ni.SumiN Offline
          Ni.Sumi
          wrote on last edited by Ni.Sumi
          #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 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 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

              • Login

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