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. Enabling the button in a QProgressDialog
Forum Updated to NodeBB v4.3 + New Features

Enabling the button in a QProgressDialog

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 2.6k 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.
  • R Offline
    R Offline
    rishabhc
    wrote on last edited by
    #1

    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

    @

    1 Reply Last reply
    0
    • F Offline
      F Offline
      Franzk
      wrote on last edited by
      #2

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

      "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • M Offline
        M Offline
        mr_gui
        wrote on last edited by
        #3

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

        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