diff options
author | Miikka Heikkinen <miikka.heikkinen@qt.io> | 2016-08-15 16:30:28 +0300 |
---|---|---|
committer | Miikka Heikkinen <miikka.heikkinen@qt.io> | 2016-08-16 06:47:44 +0000 |
commit | c6d72bb6ebd860a38aac2e557bca330b0d5b1926 (patch) | |
tree | 2f4da0685db88710361e250214f928c39c029bcf /examples/charts/callout/callout.cpp | |
parent | cccd1b688333dcc5616e1fa48050c60a1a534421 (diff) |
Fix resize handling in Callout example
Callouts are now positioned correctly when the chart is resized.
Task-number: QTBUG-54492
Change-Id: I5660eb48e58348cc2d649b48965c342488294ae4
Reviewed-by: Mika Salmela <mika.salmela@qt.io>
Reviewed-by: Miikka Heikkinen <miikka.heikkinen@qt.io>
Diffstat (limited to 'examples/charts/callout/callout.cpp')
-rw-r--r-- | examples/charts/callout/callout.cpp | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/examples/charts/callout/callout.cpp b/examples/charts/callout/callout.cpp index f20d0609..9699df61 100644 --- a/examples/charts/callout/callout.cpp +++ b/examples/charts/callout/callout.cpp @@ -24,15 +24,17 @@ #include <QtGui/QFontMetrics> #include <QtWidgets/QGraphicsSceneMouseEvent> #include <QtGui/QMouseEvent> +#include <QtCharts/QChart> -Callout::Callout(QGraphicsItem * parent): - QGraphicsItem(parent) +Callout::Callout(QChart *chart): + QGraphicsItem(chart), + m_chart(chart) { } QRectF Callout::boundingRect() const { - QPointF anchor = mapFromParent(m_anchor); + QPointF anchor = mapFromParent(m_chart->mapToPosition(m_anchor)); QRectF rect; rect.setLeft(qMin(m_rect.left(), anchor.x())); rect.setRight(qMax(m_rect.right(), anchor.x())); @@ -48,7 +50,7 @@ void Callout::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, Q QPainterPath path; path.addRoundedRect(m_rect, 5, 5); - QPointF anchor = mapFromParent(m_anchor); + QPointF anchor = mapFromParent(m_chart->mapToPosition(m_anchor)); if (!m_rect.contains(anchor)) { QPointF point1, point2; @@ -80,7 +82,7 @@ void Callout::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, Q point2.setY(y2); path.moveTo(point1); - path.lineTo(mapFromParent(m_anchor)); + path.lineTo(anchor); path.lineTo(point2); path = path.simplified(); } @@ -118,3 +120,9 @@ void Callout::setAnchor(QPointF point) { m_anchor = point; } + +void Callout::updateGeometry() +{ + prepareGeometryChange(); + setPos(m_chart->mapToPosition(m_anchor) + QPoint(10, -50)); +} |