Change text displayed by QProgressBar

Kazuma picture Kazuma · Dec 15, 2011 · Viewed 24.1k times · Source

I use a QProgressBar to show the progress of a download operation. I would like to add some text to the percentage displayed, something like:

10% (download speed kB/s)

Any idea?

Answer

Lwin Htoo Ko picture Lwin Htoo Ko · Dec 15, 2011

make the QProgressBar text visible.

QProgressBar *progBar = new QProgressBar();
progBar->setTextVisible(true);

to show the download progress

void Widget::setProgress(int downloadedSize, int totalSize)
{
    double downloaded_Size = (double)downloadedSize;
    double total_Size = (double)totalSize;
    double progress = (downloaded_Size/total_Size) * 100;
    progBar->setValue(progress);

    // ******************************************************************
    progBar->setFormat("Your text here. "+QString::number(progress)+"%");
}