PDA

View Full Version : How to increase progress bar



shivendra46d
27th August 2013, 13:46
I want too set progress bar in my Ui which increases as my code is being processed.

I am doing heavy calculation in my code to calculate the X and Y cordinates which freezes my ui for few second and i want to use progress bar to be filled in that duration any idea

wysota
27th August 2013, 14:38
You need to process events after you change the progress bar value. Alternatively you can execute your heavy calculations in a worker thread so that the UI thread remain responsive. Also see this article -- Keeping the GUI Responsive

shivendra46d
31st August 2013, 06:26
thanks a lot for the idea and can you tell me if i put my heavy calculation part on worker thread will it improve the performance? right now its taking around 5 second to calculate 5 billion points

wysota
2nd September 2013, 21:55
thanks a lot for the idea and can you tell me if i put my heavy calculation part on worker thread will it improve the performance? right now its taking around 5 second to calculate 5 billion points

No, it will not improve performance. Only modification of the algorithm (e.g. concurrent calculation on multiple threads) might do that.

shivendra46d
10th September 2013, 07:35
Thanks i did the same that you told and it worked. Also Regarding progress bar i used signals and slot it was easy and better.
Now i want to ask that i am using LinearGradient to draw line with color gradient. So it is drawing but the gradient colors are varrying by height of my widget but what i want is it to varry by width of my widget
" QLinearGradient linearGrad;
linearGrad.setCoordinateMode(QGradient::StretchToD eviceMode);
linearGrad.setStart( 0.0, 0.0 );
linearGrad.setFinalStop( 0.0, 1.0 );
linearGrad.setColorAt(1.0, QColor(0,0,255));
linearGrad.setColorAt(0.3, QColor(147,0,0));
linearGrad.setColorAt(0.0, Qt::red);

PrivewPainter.setPen(QPen(linearGrad,1));


for (int i =0; i<static_cast<int>(SRP_Widget_Width)-1; i++)
{
for (int j =0 ; j<static_cast<int>(SRP_Widget_Height)-1; j++)
{
if(Total_Intensity[j][i] !=0)
{


PrivewPainter.drawLine(i,j,i+1,j+1) ;


}
}
}"
here is my code in This Total_Intensity is a 2d vector

wysota
10th September 2013, 08:19
Change coordinates of the final stop from 0,1 to 1,0.

anda_skoa
10th September 2013, 11:12
The distribution direction is easier to see if you pass the values to the constructor



QLinearGradient grad1( 0, 0, width(), 0 ); // distribute colors over width of widget
QLinearGradient grad1( 0, 0, 0, height() ); // distribute colors over height of widget
QLinearGradient grad1( 0, 0, width(), height() ); // distribute colors over width and height of widget, diagonally


Cheers,
_

shivendra46d
11th September 2013, 13:07
Thanks guys you both helped me a lot.