The solution was small enough that I don't mind sharing. I recently tackled this problem for a project I'm working on. SetPos(m_chart->mapToPosition(m_anchor) + QPoint(10, -50)) M_textRect = metrics.boundingRect(QRect(0, 0, 250, 250), Qt::AlignLeft, m_text) Void Callout::setText(const QString &text) SetPos(mapToParent(event->pos() - event->buttonDownPos(Qt::LeftButton))) Void Callout::mouseMoveEvent(QGraphicsSceneMouseEvent *event) Void Callout::mousePressEvent(QGraphicsSceneMouseEvent *event) Qreal y2 = y + aboveCenter * 20 - belowCenter * 10 + cornerCase * vertical * (above * 20 - below * 10) Qreal x2 = x + leftOfCenter * 20 - rightOfCenter * 10 + cornerCase * !vertical * (onLeft * 20 - onRight * 10) Qreal y1 = y + aboveCenter * 10 - belowCenter * 20 + cornerCase * vertical * (above * 10 - below * 20) Qreal x1 = x + leftOfCenter * 10 - rightOfCenter * 20 + cornerCase * !vertical * (onLeft * 10 - onRight * 20) Qreal y = (below + belowCenter) * m_rect.height() īool cornerCase = (above & onLeft) || (above & onRight) || (below & onLeft) || (below & onRight) īool vertical = qAbs(anchor.x() - x) > qAbs(anchor.y() - y) Qreal x = (onRight + rightOfCenter) * m_rect.width() establish the position of the anchor point in relation to m_rectīool above = anchor.y() m_rect.top() & anchor.y() m_rect.center().y() & anchor.y() m_rect.bottom() īool onLeft = anchor.x() m_rect.left() & anchor.x() m_rect.center().x() & anchor.x() m_rect.right() Void Callout::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget) tBottom(qMax(m_rect.bottom(), anchor.y())) tRight(qMax(m_rect.right(), anchor.x())) QPointF anchor = mapFromParent(m_chart->mapToPosition(m_anchor)) An example was found in the chart documentation (QT) with similar functionality (not quite what you need), but the main problem is that the code is written in C++.īelow is the code in C++ (if it helps): #include "callout.h" Unfortunately, we didn’t succeed in making any progress.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |