Enabling the button in a QProgressDialog



  • Hello,

    I am using a QProgressDialog to show the user the progress of an operation. The cancelButton is defined to be disabled till the counter value runs to 100. I have replaced the default cancelButton to a custom one to access the setEnabled method on it. On completion of 100%, the button defined in the QProgressDialog widget should be changed from a disabled state to an enabled state.

    The code is defined as:

    @
    #include "mainwindow4.h"
    #include<QProgressBar>
    #include<QTimer>
    #include<QProgressDialog>
    #include<QPushButton>

    mainwindow4::mainwindow4(QWidget *parent) :
    QMainWindow(parent)
    {
    i=0;
    p2=new QProgressDialog("Hello World","OK",0,100);
    p2->setAutoReset(FALSE);
    QTimer *timer = new QTimer(this);
    connect(timer, SIGNAL(timeout()), this, SLOT(updatePBar()));
    timer->start(20);
    b=new QPushButton("Hello");
    b->setEnabled(FALSE);
    p2->setCancelButton(b);
    this->setCentralWidget(p2);
    }

    void mainwindow4::updatePBar()
    {
    if(p2->value()<=100)
    {
    p2->setValue(i++);
    }
    else
    updateButton();

    }

    void mainwindow4::updateButton()
    {
    b->setEnabled(TRUE);
    p2->setCancelButton(b);
    }

    @

    However, on completion of the progress, the state of the button does not change to Enabled. Any idea on what is going wrong here?

    The header is attached for reference:

    @
    #ifndef MAINWINDOW4_H
    #define MAINWINDOW4_H

    #include <QMainWindow>
    #include<QProgressBar>
    #include<QProgressDialog>
    #include<QPushButton>

    class mainwindow4 : public QMainWindow
    {
    Q_OBJECT

    private:
    QProgressBar* p;
    QProgressDialog* p2;
    QPushButton* b;
    int i;

    public:
    explicit mainwindow4(QWidget *parent = 0);

    signals:

    public slots:
    void updatePBar();
    void updateButton();
    };

    #endif // MAINWINDOW4_H

    @



  • What's the purpose of being able to cancel the dialog when the work is already finished?



  • maybe it's because you do not enter updatePBar() with a value >100? I think you should enable the cancel button on value == 100.

    anyway Franzk is right ;)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.