QProgressbar without text does not progress smoothly
The jerk with QProgressBar occurs when setTextVisible(false) is used. Condition exists to handle repaint when text visibility is true but not handled when text visibility is false. Usage of auto leads to type confusions. Add the logic to repaint for every 1 pixel change in the value when text visibility is false. Avoid using auto when type is obvious. Fixes: QTBUG-45048 Change-Id: I0fdc62c7aabdaef52bc4bdc20e82141a4a7d29d5 Reviewed-by: Axel Spoerl <axel.spoerl@qt.io> (cherry picked from commit 913b98d4120b56487a14eb96b5e5252fdd939603) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
83a749c4f9
commit
3d9a48ad37
@ -111,29 +111,33 @@ bool QProgressBarPrivate::repaintRequired() const
|
||||
if (value == lastPaintedValue)
|
||||
return false;
|
||||
|
||||
const auto valueDifference = qAbs(qint64(value) - lastPaintedValue);
|
||||
// Check if the text needs to be repainted
|
||||
const int valueDifference = qAbs(value - lastPaintedValue);
|
||||
|
||||
if (value == minimum || value == maximum)
|
||||
return true;
|
||||
|
||||
const auto totalSteps = qint64(maximum) - minimum;
|
||||
const int totalSteps = maximum - minimum;
|
||||
|
||||
const int currentPercentage = (value - minimum) * 100 / totalSteps;
|
||||
const int lastPaintedPercentage = (lastPaintedValue - minimum) * 100 / totalSteps;
|
||||
|
||||
const int percentageChangeConstant = 1;
|
||||
const bool percentageChanged = (qAbs(currentPercentage - lastPaintedPercentage) >= percentageChangeConstant);
|
||||
|
||||
if (textVisible) {
|
||||
if (format.contains("%v"_L1))
|
||||
return true;
|
||||
if (format.contains("%p"_L1) && valueDifference >= qAbs(totalSteps / 100))
|
||||
if (format.contains("%p"_L1) && percentageChanged)
|
||||
return true;
|
||||
}
|
||||
|
||||
// Check if the bar needs to be repainted
|
||||
// Check if the bar needs to be repainted based on pixel-level differences
|
||||
QStyleOptionProgressBar opt;
|
||||
q->initStyleOption(&opt);
|
||||
int cw = q->style()->pixelMetric(QStyle::PM_ProgressBarChunkWidth, &opt, q);
|
||||
QRect groove = q->style()->subElementRect(QStyle::SE_ProgressBarGroove, &opt, q);
|
||||
// This expression is basically
|
||||
// (valueDifference / (maximum - minimum) > cw / groove.width())
|
||||
// transformed to avoid integer division.
|
||||
int grooveBlock = (q->orientation() == Qt::Horizontal) ? groove.width() : groove.height();
|
||||
return valueDifference * grooveBlock > cw * totalSteps;
|
||||
const double pixelSize = static_cast<double>(totalSteps) / grooveBlock;
|
||||
return valueDifference > pixelSize;
|
||||
}
|
||||
|
||||
/*!
|
||||
|
Loading…
x
Reference in New Issue
Block a user