Fix progress bar rendering issue when using windows 11 style
The Windows 11 style checks for QProgressBar type and gets the respective orientation required for rendering. This creates an issue when we use QStyleItemDelegate as it's not QProgressBar type. This patch removes that condition and gets the orientation information through the style option similar to Windows Vista style. Fixes: QTBUG-124447 Change-Id: Ic2b36d79d7af017262e44dd2800ad45fbe63f8f2 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
This commit is contained in:
parent
a59d60d4ff
commit
3eb0c8007c
@ -1207,75 +1207,72 @@ void QWindows11Style::drawControl(ControlElement element, const QStyleOption *op
|
|||||||
break;
|
break;
|
||||||
case QStyle::CE_ProgressBarGroove:{
|
case QStyle::CE_ProgressBarGroove:{
|
||||||
if (const QStyleOptionProgressBar* progbaropt = qstyleoption_cast<const QStyleOptionProgressBar*>(option)) {
|
if (const QStyleOptionProgressBar* progbaropt = qstyleoption_cast<const QStyleOptionProgressBar*>(option)) {
|
||||||
if (const QProgressBar* bar = qobject_cast<const QProgressBar*>(widget)) {
|
QRect rect = subElementRect(SE_ProgressBarContents, progbaropt, widget);
|
||||||
QRect rect = subElementRect(SE_ProgressBarContents, progbaropt, widget);
|
QPointF center = rect.center();
|
||||||
QPointF center = rect.center();
|
if (progbaropt->state & QStyle::State_Horizontal) {
|
||||||
if (bar->orientation() & Qt::Horizontal) {
|
rect.setHeight(1);
|
||||||
rect.setHeight(1);
|
rect.moveTop(center.y());
|
||||||
rect.moveTop(center.y());
|
} else {
|
||||||
} else {
|
rect.setWidth(1);
|
||||||
rect.setWidth(1);
|
rect.moveLeft(center.x());
|
||||||
rect.moveLeft(center.x());
|
|
||||||
}
|
|
||||||
painter->setPen(Qt::NoPen);
|
|
||||||
painter->setBrush(Qt::gray);
|
|
||||||
painter->drawRect(rect);
|
|
||||||
}
|
}
|
||||||
|
painter->setPen(Qt::NoPen);
|
||||||
|
painter->setBrush(Qt::gray);
|
||||||
|
painter->drawRect(rect);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case QStyle::CE_ProgressBarContents:
|
case QStyle::CE_ProgressBarContents:
|
||||||
if (const QStyleOptionProgressBar* progbaropt = qstyleoption_cast<const QStyleOptionProgressBar*>(option)) {
|
if (const QStyleOptionProgressBar* progbaropt = qstyleoption_cast<const QStyleOptionProgressBar*>(option)) {
|
||||||
if (const QProgressBar* bar = qobject_cast<const QProgressBar*>(widget)) {
|
const qreal progressBarThickness = 3;
|
||||||
const qreal progressBarThickness = 3;
|
const qreal progressBarHalfThickness = progressBarThickness / 2.0;
|
||||||
const qreal progressBarHalfThickness = progressBarThickness / 2.0;
|
QRectF rect = subElementRect(SE_ProgressBarContents, progbaropt, widget);
|
||||||
QRectF rect = subElementRect(SE_ProgressBarContents, progbaropt, widget);
|
QRectF originalRect = rect;
|
||||||
QRectF originalRect = rect;
|
QPointF center = rect.center();
|
||||||
QPointF center = rect.center();
|
bool isIndeterminate = progbaropt->maximum == 0 && progbaropt->minimum == 0;
|
||||||
bool isIndeterminate = progbaropt->maximum == 0 && progbaropt->minimum == 0;
|
float fillPercentage = 0;
|
||||||
float fillPercentage = 0;
|
const Qt::Orientation orientation = (progbaropt->state & QStyle::State_Horizontal) ? Qt::Horizontal : Qt::Vertical;
|
||||||
const qreal offset = (bar->orientation() == Qt::Horizontal && int(rect.height()) % 2 == 0)
|
const qreal offset = (orientation == Qt::Horizontal && int(rect.height()) % 2 == 0)
|
||||||
|| (bar->orientation() == Qt::Vertical && int(rect.width()) % 2 == 0) ? 0.5 : 0.0;
|
|| (orientation == Qt::Vertical && int(rect.width()) % 2 == 0) ? 0.5 : 0.0;
|
||||||
|
|
||||||
if (!isIndeterminate) {
|
if (!isIndeterminate) {
|
||||||
fillPercentage = ((float(progbaropt->progress) - float(progbaropt->minimum)) / (float(progbaropt->maximum) - float(progbaropt->minimum)));
|
fillPercentage = ((float(progbaropt->progress) - float(progbaropt->minimum)) / (float(progbaropt->maximum) - float(progbaropt->minimum)));
|
||||||
if (bar->orientation() == Qt::Horizontal) {
|
if (orientation == Qt::Horizontal) {
|
||||||
rect.setHeight(progressBarThickness);
|
rect.setHeight(progressBarThickness);
|
||||||
rect.moveTop(center.y() - progressBarHalfThickness - offset);
|
rect.moveTop(center.y() - progressBarHalfThickness - offset);
|
||||||
rect.setWidth(rect.width() * fillPercentage);
|
rect.setWidth(rect.width() * fillPercentage);
|
||||||
} else {
|
|
||||||
float oldHeight = rect.height();
|
|
||||||
rect.setWidth(progressBarThickness);
|
|
||||||
rect.moveLeft(center.x() - progressBarHalfThickness - offset);
|
|
||||||
rect.moveTop(oldHeight * (1.0f - fillPercentage));
|
|
||||||
rect.setHeight(oldHeight * fillPercentage);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
auto elapsedTime = std::chrono::time_point_cast<std::chrono::milliseconds>(std::chrono::system_clock::now());
|
float oldHeight = rect.height();
|
||||||
fillPercentage = (elapsedTime.time_since_epoch().count() % 5000)/(5000.0f*0.75);
|
rect.setWidth(progressBarThickness);
|
||||||
if (bar->orientation() == Qt::Horizontal) {
|
rect.moveLeft(center.x() - progressBarHalfThickness - offset);
|
||||||
float barBegin = qMin(qMax(fillPercentage-0.25,0.0) * rect.width(), float(rect.width()));
|
rect.moveTop(oldHeight * (1.0f - fillPercentage));
|
||||||
float barEnd = qMin(fillPercentage * rect.width(), float(rect.width()));
|
rect.setHeight(oldHeight * fillPercentage);
|
||||||
rect = QRect(QPoint(rect.left() + barBegin, rect.top()), QPoint(rect.left() + barEnd, rect.bottom()));
|
|
||||||
rect.setHeight(progressBarThickness);
|
|
||||||
rect.moveTop(center.y() - progressBarHalfThickness - offset);
|
|
||||||
} else {
|
|
||||||
float barBegin = qMin(qMax(fillPercentage-0.25,0.0) * rect.height(), float(rect.height()));
|
|
||||||
float barEnd = qMin(fillPercentage * rect.height(), float(rect.height()));
|
|
||||||
rect = QRect(QPoint(rect.left(), rect.bottom() - barEnd), QPoint(rect.right(), rect.bottom() - barBegin));
|
|
||||||
rect.setWidth(progressBarThickness);
|
|
||||||
rect.moveLeft(center.x() - progressBarHalfThickness - offset);
|
|
||||||
}
|
|
||||||
const_cast<QWidget*>(widget)->update();
|
|
||||||
}
|
}
|
||||||
if (progbaropt->invertedAppearance && bar->orientation() == Qt::Horizontal)
|
} else {
|
||||||
rect.moveLeft(originalRect.width() * (1.0 - fillPercentage));
|
auto elapsedTime = std::chrono::time_point_cast<std::chrono::milliseconds>(std::chrono::system_clock::now());
|
||||||
else if (progbaropt->invertedAppearance && bar->orientation() == Qt::Vertical)
|
fillPercentage = (elapsedTime.time_since_epoch().count() % 5000)/(5000.0f*0.75);
|
||||||
rect.moveBottom(originalRect.height() * fillPercentage);
|
if (orientation == Qt::Horizontal) {
|
||||||
painter->setPen(Qt::NoPen);
|
float barBegin = qMin(qMax(fillPercentage-0.25,0.0) * rect.width(), float(rect.width()));
|
||||||
painter->setBrush(progbaropt->palette.accent());
|
float barEnd = qMin(fillPercentage * rect.width(), float(rect.width()));
|
||||||
painter->drawRoundedRect(rect, secondLevelRoundingRadius, secondLevelRoundingRadius);
|
rect = QRect(QPoint(rect.left() + barBegin, rect.top()), QPoint(rect.left() + barEnd, rect.bottom()));
|
||||||
|
rect.setHeight(progressBarThickness);
|
||||||
|
rect.moveTop(center.y() - progressBarHalfThickness - offset);
|
||||||
|
} else {
|
||||||
|
float barBegin = qMin(qMax(fillPercentage-0.25,0.0) * rect.height(), float(rect.height()));
|
||||||
|
float barEnd = qMin(fillPercentage * rect.height(), float(rect.height()));
|
||||||
|
rect = QRect(QPoint(rect.left(), rect.bottom() - barEnd), QPoint(rect.right(), rect.bottom() - barBegin));
|
||||||
|
rect.setWidth(progressBarThickness);
|
||||||
|
rect.moveLeft(center.x() - progressBarHalfThickness - offset);
|
||||||
|
}
|
||||||
|
const_cast<QWidget*>(widget)->update();
|
||||||
}
|
}
|
||||||
|
if (progbaropt->invertedAppearance && orientation == Qt::Horizontal)
|
||||||
|
rect.moveLeft(originalRect.width() * (1.0 - fillPercentage));
|
||||||
|
else if (progbaropt->invertedAppearance && orientation == Qt::Vertical)
|
||||||
|
rect.moveBottom(originalRect.height() * fillPercentage);
|
||||||
|
painter->setPen(Qt::NoPen);
|
||||||
|
painter->setBrush(progbaropt->palette.accent());
|
||||||
|
painter->drawRoundedRect(rect, secondLevelRoundingRadius, secondLevelRoundingRadius);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case QStyle::CE_ProgressBarLabel:
|
case QStyle::CE_ProgressBarLabel:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user