how to make the progress bar run smoothly
-
how do you make the progress bar run smoothly, I mean smooth is if the initial value is 0 then the process value jumps to 50 the progress bar runs from 0 to 50 smoothly instead of jumping directly from 0 to 50, I hope you understand, this is an example of code from C# that makes the progress bar smooth, this is not a thread problem but how to make the progress bar run smoothly
private void SetProgressBarPosition(ProgressBar progressBar, int position) { bool invokeRequired = progressBar.InvokeRequired; if (invokeRequired) { FormMain.SetProgressBarPositionCallBack method = new FormMain.SetProgressBarPositionCallBack(this.SetProgressBarPosition); progressBar.Invoke(method, new object[] { progressBar, position }); } else { progressBar.Value = position; } } -
how do you make the progress bar run smoothly, I mean smooth is if the initial value is 0 then the process value jumps to 50 the progress bar runs from 0 to 50 smoothly instead of jumping directly from 0 to 50, I hope you understand, this is an example of code from C# that makes the progress bar smooth, this is not a thread problem but how to make the progress bar run smoothly
private void SetProgressBarPosition(ProgressBar progressBar, int position) { bool invokeRequired = progressBar.InvokeRequired; if (invokeRequired) { FormMain.SetProgressBarPositionCallBack method = new FormMain.SetProgressBarPositionCallBack(this.SetProgressBarPosition); progressBar.Invoke(method, new object[] { progressBar, position }); } else { progressBar.Value = position; } }@Blackzero
We can't say anything from this code. What range doespositiontake, how often do you call it with what values, does it make any difference whetherinvokeRequiredis true or false, do you run this in a different thread from the main thread, ... ? The progressbar does "run smoothly" if you set its value correctly and over time. Try it in C++ or Python. -
how do you make the progress bar run smoothly, I mean smooth is if the initial value is 0 then the process value jumps to 50 the progress bar runs from 0 to 50 smoothly instead of jumping directly from 0 to 50, I hope you understand, this is an example of code from C# that makes the progress bar smooth, this is not a thread problem but how to make the progress bar run smoothly
private void SetProgressBarPosition(ProgressBar progressBar, int position) { bool invokeRequired = progressBar.InvokeRequired; if (invokeRequired) { FormMain.SetProgressBarPositionCallBack method = new FormMain.SetProgressBarPositionCallBack(this.SetProgressBarPosition); progressBar.Invoke(method, new object[] { progressBar, position }); } else { progressBar.Value = position; } }@Blackzero said in how to make the progress bar run smoothly:
how do you make the progress bar run smoothly
Simple:
Connect a signal from your non-blocking "work" task to
QProgressBar::setValue(int).
If the task whose status is represented by the progressbar is blocking and unblocks at 50% first, you will see that jump.
( And also, if you have no progress and suddenly set a value of 50... the progress bar will go from 0 to 50 instantly )Say you have a worker with some intense computing task
// ##################### // Worker class in different thread for ( int i = 0; i < 100; ++i ) { QThread::sleep(1); // simulate 1s of "work" int progress = i; emit progressDone(progress); } // #################### // ####################### // MainWindow where ProgressBar is QProgressBar *progressBar = new QProgressBar(this); progressBar->setRange(0, 100); Worker w; // worker setup here // ... connect (&w, &Worker::progressDone, this, [=](int progress) { progressBar->setValue(progress); });This whole thing also works without any worker thread... if you want to update your bar, just use
progressBar->setValue(progress)to set your progress value. Then you have that "jump" again.See also the
QProgressDialogdocumentation:There is shown how to update the bar and show the actual progress of some task.
-
@Blackzero said in how to make the progress bar run smoothly:
how do you make the progress bar run smoothly
Simple:
Connect a signal from your non-blocking "work" task to
QProgressBar::setValue(int).
If the task whose status is represented by the progressbar is blocking and unblocks at 50% first, you will see that jump.
( And also, if you have no progress and suddenly set a value of 50... the progress bar will go from 0 to 50 instantly )Say you have a worker with some intense computing task
// ##################### // Worker class in different thread for ( int i = 0; i < 100; ++i ) { QThread::sleep(1); // simulate 1s of "work" int progress = i; emit progressDone(progress); } // #################### // ####################### // MainWindow where ProgressBar is QProgressBar *progressBar = new QProgressBar(this); progressBar->setRange(0, 100); Worker w; // worker setup here // ... connect (&w, &Worker::progressDone, this, [=](int progress) { progressBar->setValue(progress); });This whole thing also works without any worker thread... if you want to update your bar, just use
progressBar->setValue(progress)to set your progress value. Then you have that "jump" again.See also the
QProgressDialogdocumentation:There is shown how to update the bar and show the actual progress of some task.
-
@Pl45m4
Yep, except all this needs writing for C#, where I don't even know if/how they haveemit,connect(), threads, etc. :)@JonB said in how to make the progress bar run smoothly:
Yep, except all this needs writing for C#
I think @Blackzero just wanted to refer to the C# snippet he is familiar with and where everything works as expected.
Now he wants to know how to do this in C++ withQProgressBar?!
But maybe I'm wrong.
The code above is WinForms C# code... no Qt involved there... -
@JonB said in how to make the progress bar run smoothly:
Yep, except all this needs writing for C#
I think @Blackzero just wanted to refer to the C# snippet he is familiar with and where everything works as expected.
Now he wants to know how to do this in C++ withQProgressBar?!
But maybe I'm wrong.
The code above is WinForms C# code... no Qt involved there... -
how do you make the progress bar run smoothly, I mean smooth is if the initial value is 0 then the process value jumps to 50 the progress bar runs from 0 to 50 smoothly instead of jumping directly from 0 to 50, I hope you understand, this is an example of code from C# that makes the progress bar smooth, this is not a thread problem but how to make the progress bar run smoothly
private void SetProgressBarPosition(ProgressBar progressBar, int position) { bool invokeRequired = progressBar.InvokeRequired; if (invokeRequired) { FormMain.SetProgressBarPositionCallBack method = new FormMain.SetProgressBarPositionCallBack(this.SetProgressBarPosition); progressBar.Invoke(method, new object[] { progressBar, position }); } else { progressBar.Value = position; } }@JonB I think this:
@Blackzero said in how to make the progress bar run smoothly:
progressBar.Value = position;
equals this
I guess... but... whatever... no idea. That's the reason why one should create understandable topics and ask clear questions...
¯\_(ツ)_/¯
@JonB said in how to make the progress bar run smoothly:
else he wouldn't have even come across it.... I think :)
Port existing C# WinForms App to Qt and C++?!
Found working C# snippet online, but no idea how to translate this to C++...
Many reasons ;-)You see people asking "I have this Python code. What is this in C++?" on StackOverflow regularly...
Understandable that so many people are annoyed there. ;-)But back to the topic :)
Only @Blackzero can answer all this, everything else is just guesswork :) -
@Blackzero said in how to make the progress bar run smoothly:
how do you make the progress bar run smoothly
Simple:
Connect a signal from your non-blocking "work" task to
QProgressBar::setValue(int).
If the task whose status is represented by the progressbar is blocking and unblocks at 50% first, you will see that jump.
( And also, if you have no progress and suddenly set a value of 50... the progress bar will go from 0 to 50 instantly )Say you have a worker with some intense computing task
// ##################### // Worker class in different thread for ( int i = 0; i < 100; ++i ) { QThread::sleep(1); // simulate 1s of "work" int progress = i; emit progressDone(progress); } // #################### // ####################### // MainWindow where ProgressBar is QProgressBar *progressBar = new QProgressBar(this); progressBar->setRange(0, 100); Worker w; // worker setup here // ... connect (&w, &Worker::progressDone, this, [=](int progress) { progressBar->setValue(progress); });This whole thing also works without any worker thread... if you want to update your bar, just use
progressBar->setValue(progress)to set your progress value. Then you have that "jump" again.See also the
QProgressDialogdocumentation:There is shown how to update the bar and show the actual progress of some task.
@Pl45m4 said in how to make the progress bar run smoothly:
Hubungkan sinyal dari tugas "pekerjaan" non-pemblokiran Anda ke QProgressBar::setValue(int).
Jika tugas yang statusnya diwakili oleh bilah kemajuan memblokir dan membuka blokir pada 50% terlebih dahulu, Anda akan melihat lompatan tersebut.
(Dan juga, jika Anda tidak mengalami kemajuan dan tiba-tiba menetapkan nilai 50... bilah kemajuan akan langsung berubah dari 0 menjadi 50)Katakanlah Anda memiliki seorang pekerja dengan tugas komputasi yang intens
I use multi-threading and there is no problem with threads but my process adjusts the transfer speed why the value is sometimes not arranged from 1 to 100 so how can I make the progressbar run like a normal process even though the value jumps from 0 to 30 or 50, I hope you understand what I mean with this confusing question
-
@Pl45m4 said in how to make the progress bar run smoothly:
Hubungkan sinyal dari tugas "pekerjaan" non-pemblokiran Anda ke QProgressBar::setValue(int).
Jika tugas yang statusnya diwakili oleh bilah kemajuan memblokir dan membuka blokir pada 50% terlebih dahulu, Anda akan melihat lompatan tersebut.
(Dan juga, jika Anda tidak mengalami kemajuan dan tiba-tiba menetapkan nilai 50... bilah kemajuan akan langsung berubah dari 0 menjadi 50)Katakanlah Anda memiliki seorang pekerja dengan tugas komputasi yang intens
I use multi-threading and there is no problem with threads but my process adjusts the transfer speed why the value is sometimes not arranged from 1 to 100 so how can I make the progressbar run like a normal process even though the value jumps from 0 to 30 or 50, I hope you understand what I mean with this confusing question
You still did not mention if you are talking about
QProgressBarand C++ code.
Why the WinForms C# example?@Blackzero said in how to make the progress bar run smoothly:
how can I make the progressbar run like a normal process even though the value jumps from 0 to 30 or 50
I hope you understand what I mean with this confusing questionSorry no I dont. The
QProgressBardoes not "run". You have to control the progress yourself. There is no animation or something like that by default, so that you see a "flow".
After some progress is done, you have to update the bar (and set/increase the value). -
You still did not mention if you are talking about
QProgressBarand C++ code.
Why the WinForms C# example?@Blackzero said in how to make the progress bar run smoothly:
how can I make the progressbar run like a normal process even though the value jumps from 0 to 30 or 50
I hope you understand what I mean with this confusing questionSorry no I dont. The
QProgressBardoes not "run". You have to control the progress yourself. There is no animation or something like that by default, so that you see a "flow".
After some progress is done, you have to update the bar (and set/increase the value).@Pl45m4 said in how to make the progress bar run smoothly:
Sorry no I dont. The QProgressBar does not "run". You have to control the progress yourself. There is no animation or something like that by default, so that you see a "flow".
After some progress is done, you have to update the bar (and set/increase the value).okay I have found a way, yes it uses QPropertyAnimation
void MainWindow::UpdateProgresBar(int value) { QPropertyAnimation *animation = new QPropertyAnimation(ui->progressBar, "value"); animation->setDuration(1000); animation->setStartValue(ui->progressBar->value()); animation->setEndValue(value); animation->setEasingCurve(QEasingCurve::Linear); animation->start(QAbstractAnimation::DeleteWhenStopped); } -
@Pl45m4 said in how to make the progress bar run smoothly:
Sorry no I dont. The QProgressBar does not "run". You have to control the progress yourself. There is no animation or something like that by default, so that you see a "flow".
After some progress is done, you have to update the bar (and set/increase the value).okay I have found a way, yes it uses QPropertyAnimation
void MainWindow::UpdateProgresBar(int value) { QPropertyAnimation *animation = new QPropertyAnimation(ui->progressBar, "value"); animation->setDuration(1000); animation->setStartValue(ui->progressBar->value()); animation->setEndValue(value); animation->setEasingCurve(QEasingCurve::Linear); animation->start(QAbstractAnimation::DeleteWhenStopped); }@Blackzero
So by using this it moves from empty to full in precisely 1 second without any input/messages about the progress of whatever it is supposed to track (such as progress in a computation or whatever). So it isn't a "progress" bar any more, it's just an animation, didn't know that is what you really wanted. -
@Blackzero
So by using this it moves from empty to full in precisely 1 second without any input/messages about the progress of whatever it is supposed to track (such as progress in a computation or whatever). So it isn't a "progress" bar any more, it's just an animation, didn't know that is what you really wanted.@JonB said in how to make the progress bar run smoothly:
empty to full in precisely 1 second without any input/messages
If @Blackzero code works as expected, the animated bar will start from current value and end on the value which is passed to the function. So not 0 -100% every time?!
-
@JonB said in how to make the progress bar run smoothly:
empty to full in precisely 1 second without any input/messages
If @Blackzero code works as expected, the animated bar will start from current value and end on the value which is passed to the function. So not 0 -100% every time?!
-
@Pl45m4 said in how to make the progress bar run smoothly:
Sorry no I dont. The QProgressBar does not "run". You have to control the progress yourself. There is no animation or something like that by default, so that you see a "flow".
After some progress is done, you have to update the bar (and set/increase the value).okay I have found a way, yes it uses QPropertyAnimation
void MainWindow::UpdateProgresBar(int value) { QPropertyAnimation *animation = new QPropertyAnimation(ui->progressBar, "value"); animation->setDuration(1000); animation->setStartValue(ui->progressBar->value()); animation->setEndValue(value); animation->setEasingCurve(QEasingCurve::Linear); animation->start(QAbstractAnimation::DeleteWhenStopped); }@Blackzero said in how to make the progress bar run smoothly:
okay I have found a way, yes it uses QPropertyAnimation
The whole guessing could have been avoided if you have said that you are looking for an animated
QProgressBar.
Nobody knew what you had in mind when you were showing the C# code and said you want your progress bar to "run smoothly" ;-) -
@Blackzero said in how to make the progress bar run smoothly:
okay I have found a way, yes it uses QPropertyAnimation
The whole guessing could have been avoided if you have said that you are looking for an animated
QProgressBar.
Nobody knew what you had in mind when you were showing the C# code and said you want your progress bar to "run smoothly" ;-)@Pl45m4 said in how to make the progress bar run smoothly:
Tidak ada yang tahu apa yang ada dalam pikiran Anda ketika Anda menunjukkan kode C# dan mengatakan Anda ingin bilah kemajuan Anda "berjalan lancar" ;-)
I find it hard to explain because I don't know much about Qt.
-
B Blackzero has marked this topic as solved on