Results 1 to 1 of 1

Thread: How do I modify the Callout example to support multiple y axes on the same side?

  1. #1
    Join Date
    Jun 2018
    Qt products

    Default How do I modify the Callout example to support multiple y axes on the same side?

    Link for Callout example in Qt's official documentation

    This example basically displays a line series and a spline series in a scene inside a qgraphicsview and everytime we hover over any point on the line, it displays the corresponding tooltip and if we click on that particular point, the tooltip stays there permanently until the program is closed.

    This example is made for charts with a single x axis and a single y axis. What I am trying to do is to implement this in a chart with multiple y axes, on the left side. I tried to use QValueAxis for this purpose: I defined axisX that is to be shared by both the series and two axes Y1 and Y2, one for each series. In the original example, createdefaultaxes() was used to create the single x and single y axis. Here's my code for the QValueAxis part:

    Qt Code:
    1. QValueAxis *axisX = new QValueAxis;
    2. QValueAxis *axisY1 = new QValueAxis;
    3. QValueAxis *axisY2 = new QValueAxis;
    5. m_chart->addAxis(axisX, Qt::AlignBottom);
    6. m_chart->addAxis(axisY1, Qt::AlignLeft);
    7. m_chart->addAxis(axisY2, Qt::AlignLeft);
    9. series->attachAxis(axisX);
    10. series->attachAxis(axisY1);
    11. series2->attachAxis(axisX);
    12. series2->attachAxis(axisY2);
    14. m_chart->setAcceptHoverEvents(true);
    16. setRenderHint(QPainter::Antialiasing);
    17. scene()->addItem(m_chart);
    19. connect(series, &QLineSeries::clicked, this, &View::keepCallout);
    20. connect(series, &QLineSeries::hovered, this, &View::tooltip);
    22. connect(series2, &QSplineSeries::clicked, this, &View::keepCallout);
    23. connect(series2, &QSplineSeries::hovered, this, &View::tooltip);
    25. this->setMouseTracking(true);
    27. // keepCallout() function
    28. {
    29. m_callouts.append(m_tooltip);//m_callouts is a QList of "Callout" class type
    30. m_tooltip = new Callout(m_chart);
    31. }
    33. //tooltip(QPointF point, bool state) function
    34. {
    35. if (m_tooltip == 0)
    36. m_tooltip = new Callout(m_chart);
    38. if (state) {
    39. m_tooltip->setText(QString("X: %1 \nY: %2").arg(point.x()).arg(point.y()));
    40. m_tooltip->setAnchor(point);
    41. m_tooltip->setZValue(11);
    42. m_tooltip->updateGeometry();
    43. m_tooltip->show();
    44. } else {
    45. m_tooltip->hide();
    46. }
    47. }
    To copy to clipboard, switch view to plain text mode 

    Result with single y axis:
    Result with multiple y axis (the tooltip appears at some distance perpendicularly below the mouse pointer)

    So yeah that's the problem. I can't seem to get the tooltip to appear at the point where my mouse is hovering. Instead it appears at a point which is at a small distance from that point.

    As for the Callout code, I can't seem to figure out which code snippets from the entire code are the most relevant in context of this question (I'm kindof a beginner in qgraphics stuff) so this is the link for the entire. It would be great if someone could help me out here. Also, since I'm new here, please let me know if there are any changes I need to make while asking questions like these.
    Attached Images Attached Images

Similar Threads

  1. Qwt with multi axes support
    By Uwe in forum Qwt
    Replies: 13
    Last Post: 8th September 2017, 12:39
  2. Scrollbar multiple y-axes
    By StrikeByte in forum Qwt
    Replies: 0
    Last Post: 14th January 2015, 15:06
  3. Replies: 11
    Last Post: 11th September 2013, 08:59
  4. Multiple Y-axis on the same side
    By ghm in forum Qwt
    Replies: 0
    Last Post: 10th October 2011, 10:46
  5. Multiple axes with a relation
    By pkj in forum Qwt
    Replies: 1
    Last Post: 21st February 2011, 07:46

Tags for this Thread


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.