However, selecting the best crosshair for your needs can be difficult. In Overwatch 2, the crosshair you use is more important than ever because the 5v5 environment encourages you to think and aim faster. If (!m_chart->plotArea().contains(position))ĭeclare a member variable in view.h and instantiate it in the constructor.Crosshairs are a useful tool that affects how you aim. M_yText->setPos(m_chart->plotArea().right(), position.y() - m_yText->boundingRect().height() / 2.0) M_xText->setPos(position.x() - m_xText->boundingRect().width() / 2.0, m_chart->plotArea().bottom()) M_yText->setHtml(QString("") + yText + "") M_xText->setHtml(QString("") + xText + "") YText = QString("%1").arg(m_chart->mapToValue(position).y()) QString xText = QString("%1").arg(m_chart->mapToValue(position).x()), M_chart->plotArea().right(), position.y()) QLineF yLine(m_chart->plotArea().left(), position.y(), Position.x(), m_chart->plotArea().bottom()) QLineF xLine(position.x(), m_chart->plotArea().top(), Void Crosshairs::updatePosition(QPointF position) M_yText->document()->setDocumentMargin(0) M_xText->document()->setDocumentMargin(0) It's possible you won't need the QChartGlobal include or NAMESPACE macros in your adaptation. My prototype was implemented right in the callout example. I know this isn't styled exactly as your mockup, but hopefully it is enough to get you started. 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.Thanks to the example, there is an understanding of how to get the mouse coordinates (code updated).It is necessary: Add crosshair with signed values to the chart (QtChart). Code: from random import uniformįrom PyQt5.QtWidgets import QApplication, QMainWindow, QVBoxLayout, QWidgetįrom PyQt5.QtChart import QChart, QChartView, QLineSeries
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |