summaryrefslogtreecommitdiffstats
path: root/examples/widgets
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@qt.io>2021-04-16 21:24:45 +0200
committerShawn Rutledge <shawn.rutledge@qt.io>2021-04-19 19:56:25 +0200
commit76537c065aea1cb3926796f6a34eb39eb81f605f (patch)
tree9159bbaf958c09e5a04c5114136541d198a23a74 /examples/widgets
parent8f429ac92682f13ac3432c9acdce5ca7cac0e68f (diff)
Avoid divide-by-zero in the gradients example
After 7a738daa97436478a21b5dd31ba2312b2cb2df41 we require QLineF::setLength() to take a finite length, and this code was probably always risky when HoverPoints has two points that are both 0,0. It's probably a transient condition anyway. Fixes: QTBUG-92908 Change-Id: If81122d2f78761026b0d656ceffe173132751317 Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
Diffstat (limited to 'examples/widgets')
-rw-r--r--examples/widgets/painting/gradients/gradients.cpp2
1 files changed, 2 insertions, 0 deletions
diff --git a/examples/widgets/painting/gradients/gradients.cpp b/examples/widgets/painting/gradients/gradients.cpp
index 76d5818d32..045da2b0c0 100644
--- a/examples/widgets/painting/gradients/gradients.cpp
+++ b/examples/widgets/painting/gradients/gradients.cpp
@@ -105,6 +105,8 @@ uint ShadeWidget::colorAt(int x)
for (int i = 1; i < pts.size(); ++i) {
if (pts.at(i - 1).x() <= x && pts.at(i).x() >= x) {
QLineF l(pts.at(i - 1), pts.at(i));
+ if (qIsNull(l.dx()))
+ continue;
l.setLength(l.length() * ((x - l.x1()) / l.dx()));
return m_shade.pixel(qRound(qMin(l.x2(), (qreal(m_shade.width() - 1)))),
qRound(qMin(l.y2(), qreal(m_shade.height() - 1))));