aboutsummaryrefslogtreecommitdiffstats
path: root/src/imports/nativestyle/items
diff options
context:
space:
mode:
authorJan Arve Sæther <jan-arve.saether@qt.io>2020-08-20 16:48:57 +0200
committerJan Arve Sæther <jan-arve.saether@qt.io>2020-09-09 14:14:34 +0200
commita40192644574daf694f70bbe1661487eb06fef68 (patch)
tree555e6d2d822e5b0bcd7247789a575c819144a8ef /src/imports/nativestyle/items
parent2520de0974649b6d720cc75b60024237b1b5ae4f (diff)
Fix ProgressBar on Windows
Also remove the two custom progress bars from the manual test where one has a custom background, and the other has a custom contentItem. If you want to customize a progress bar, you need to provide customizations for both the background and the contentItem. You cannot provide a custom background (or contentItem) alone, since its almost impossible to create a custom background that fits well with the contentItem of all the other possible styles it might be using. Change-Id: I82a87513e73f319bcecbfaed341ac4949f64c3bb Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io>
Diffstat (limited to 'src/imports/nativestyle/items')
-rw-r--r--src/imports/nativestyle/items/qquickstyleitemprogressbar.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/imports/nativestyle/items/qquickstyleitemprogressbar.cpp b/src/imports/nativestyle/items/qquickstyleitemprogressbar.cpp
index 3429b5ac..8042d35a 100644
--- a/src/imports/nativestyle/items/qquickstyleitemprogressbar.cpp
+++ b/src/imports/nativestyle/items/qquickstyleitemprogressbar.cpp
@@ -57,7 +57,15 @@ StyleItemGeometry QQuickStyleItemProgressBar::calculateGeometry()
StyleItemGeometry geometry;
geometry.minimumSize = style()->sizeFromContents(QStyle::CT_ProgressBar, &styleOption, QSize(0, 0));
- geometry.implicitSize = geometry.minimumSize;
+
+ // From qprogressbar.cpp in qtbase:
+ const int cw = style()->pixelMetric(QStyle::PM_ProgressBarChunkWidth, &styleOption);
+ QFontMetrics fm(control<QQuickProgressBar>()->font());
+ QSize size = QSize(qMax(9, cw) * 7 + fm.horizontalAdvance(QLatin1Char('0')) * 4, fm.height() + 8);
+ if (!(styleOption.state & QStyle::State_Horizontal))
+ size = size.transposed();
+
+ geometry.implicitSize = style()->sizeFromContents(QStyle::CT_ProgressBar, &styleOption, size);
styleOption.rect = QRect(QPoint(0, 0), geometry.implicitSize);
geometry.contentRect = style()->subElementRect(QStyle::SE_ProgressBarContents, &styleOption);
geometry.layoutRect = style()->subElementRect(QStyle::SE_ProgressBarLayoutItem, &styleOption);
@@ -74,6 +82,10 @@ void QQuickStyleItemProgressBar::paintEvent(QPainter *painter)
styleOption.rect = style()->subElementRect(QStyle::SE_ProgressBarGroove, &styleOption);
style()->drawControl(QStyle::CE_ProgressBarGroove, &styleOption, painter);
} else {
+ const QRect r = styleOption.rect;
+ styleOption.rect = style()->subElementRect(QStyle::SE_ProgressBarGroove, &styleOption);
+ style()->drawControl(QStyle::CE_ProgressBarGroove, &styleOption, painter);
+ styleOption.rect = r;
styleOption.rect = style()->subElementRect(QStyle::SE_ProgressBarContents, &styleOption);
style()->drawControl(QStyle::CE_ProgressBarContents, &styleOption, painter);
}