adnan kamili
adnan kamili

Reputation: 9455

How to create a custom multi-progress bar in Qt

I am working on a multi -segment download manager. I want to display the segmentation procedure. QGraphicsScene works fine but , unfortunately it slows the download. Is there any better option, other than using QProgressBars. I am using QNetworkAccessManager to download files. If I connect the downloadProgress signal of QNetworkManager object to a slot of Main Gui Thread which draws on QGraphicsView, the download speed decreases even upto 10 times in some cases

    // a custom progress bar
void Download::showGProgress(int num, float prgrss)                                 //slot
{
    prgrss=prgrss/100;
    x_coord=(ui->graphicsView_2->width()-3)*prgrss;                              
    for(float b=0;b<=x_coord;b=b+0.5)
    {
        progress.addRect(0,0,x_coord,y_coord);

    }

}

Upvotes: 0

Views: 2933

Answers (3)

jdi
jdi

Reputation: 92587

QNetworkAccessManager is not threaded. It is asynchronous, using the current threads eventloop. It is the HTTP requests which it create that are the threaded aspect.

This would explain why anything you do in your main thread could theoretically slow down the operations of the download. Though not necessarily the underlying threaded download itself, but rather the signaling response time that would allow you to have fast feedback about it.

What you should probably do is create your own QThread subclass, and create the QNetworkAccessManager in the run() method. And then create a QEventLoop in the thread and call exec()

In a nutshell, you need to create your own Threaded QNetworkAccessManager.

Upvotes: 1

Kharec
Kharec

Reputation: 68

Did you try QProgressBar? Maybe you can write a subclass of it to handle your own properties.

Upvotes: 0

g19fanatic
g19fanatic

Reputation: 10941

create your own widget to do what you would like

this is easier than it sounds.

Make a class that subclasses from a QWidget. And in this widget make a Horizontal Sizer that contains 100 Qlabels (store the QLabels in a vector). Give it slots to 'update' the current progress by setting the background color of each QLabel to a different color. This should be fairly easy to do progressively, meaning you store the current 'percentage' as a member variable and then only adjust the fields that are necessary to get to the percentage that you're looking for (This will eliminate some flickering if you were to do it from scratch every time).

Add functions that will switch the sizer to a vertical one instead of a horizontal one to make it even more customizable.

This allows you to get creative in the what you can do for the progress bar as each element could be a different picture, or a different color, or whatever you would like.

Upvotes: 1

Related Questions