Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to find which axis has been clicked on a QChartView
Forum Updated to NodeBB v4.3 + New Features

How to find which axis has been clicked on a QChartView

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 155 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kehr_I
    wrote last edited by
    #1

    I've got the following situation:

    There is a chart with several QXYSeries added to it. Let's assume, that there are more than one QAbstractAxis objects for each alignment (eg. 2 on the right, 2 on the left, 2 on the bottom - I'm not questioning the feature request here).

    The user performs a right click on one of the axes to have a context menu to access the respective axis properties.

    The widget does receive the respective click event, so the clicked point on the scene is known.

    Question: How to I find out, given the point on the view, which axis has been clicked?
    The question is actually not that trivial. For the legend, I could just go over the childItems of the QGraphicsView and find the legend object, by checking whether the clicked point is within its boundingRect. But for the axes-types, this is implemented as return QRect();, so, not really helpful. Also, I cannot check for its children, because the axes items don't add their inner items as children. The actual type, even though I can look into the code, is package private, so I also cannot cast to it to retrieve the inner items.

    Suggestions?

    I'm using Qt 6.8.3 on win11.

    JonBJ 1 Reply Last reply
    0
    • K kehr_I

      I've got the following situation:

      There is a chart with several QXYSeries added to it. Let's assume, that there are more than one QAbstractAxis objects for each alignment (eg. 2 on the right, 2 on the left, 2 on the bottom - I'm not questioning the feature request here).

      The user performs a right click on one of the axes to have a context menu to access the respective axis properties.

      The widget does receive the respective click event, so the clicked point on the scene is known.

      Question: How to I find out, given the point on the view, which axis has been clicked?
      The question is actually not that trivial. For the legend, I could just go over the childItems of the QGraphicsView and find the legend object, by checking whether the clicked point is within its boundingRect. But for the axes-types, this is implemented as return QRect();, so, not really helpful. Also, I cannot check for its children, because the axes items don't add their inner items as children. The actual type, even though I can look into the code, is package private, so I also cannot cast to it to retrieve the inner items.

      Suggestions?

      I'm using Qt 6.8.3 on win11.

      JonBJ Online
      JonBJ Online
      JonB
      wrote last edited by
      #2

      @kehr_I
      Per https://forum.qt.io/topic/151962/implementing-individual-y-axis-zoom-on-multi-axis-qchart-need-help-with-axis-position the indication is that information about axes positions may not be available unless you do change the Qt source code?

      K 1 Reply Last reply
      0
      • JonBJ JonB

        @kehr_I
        Per https://forum.qt.io/topic/151962/implementing-individual-y-axis-zoom-on-multi-axis-qchart-need-help-with-axis-position the indication is that information about axes positions may not be available unless you do change the Qt source code?

        K Offline
        K Offline
        kehr_I
        wrote last edited by
        #3

        @JonB Thanks for your answer

        The post you mention states, what I've been asking about.

        They found, that there is no way with an unpatched QChart/View to retrieve the object under the mouse.

        This is rather sad to be honest.

        Is there a way to add that as a feature request?

        QObject* objectAt(QPointF const& p) const;
        

        Which provides items of type QAbstractSeries* if the point happens to be on a series, a QAbstractAxis* if the point happens to be on an axis, a legend object if...

        JonBJ 1 Reply Last reply
        0
        • K kehr_I

          @JonB Thanks for your answer

          The post you mention states, what I've been asking about.

          They found, that there is no way with an unpatched QChart/View to retrieve the object under the mouse.

          This is rather sad to be honest.

          Is there a way to add that as a feature request?

          QObject* objectAt(QPointF const& p) const;
          

          Which provides items of type QAbstractSeries* if the point happens to be on a series, a QAbstractAxis* if the point happens to be on an axis, a legend object if...

          JonBJ Online
          JonBJ Online
          JonB
          wrote last edited by
          #4

          @kehr_I said in How to find which axis has been clicked on a QChartView:

          The post you mention states, what I've been asking about.

          They found, that there is no way with an unpatched QChart/View to retrieve the object under the mouse.

          Yes, because I was a responder there :)

          There is no point at all in submitting such a feature request since if you read around you will find QtCharts is in the process of being replaced by QtGraphs, and no new changes will be made to QtCharts. You might as well change the source yourself in this light.

          You could try changing over to QtGraphs to see if anything else there helps. However, from what little I know but have seen in some posts here I am not at all sure QtGraphs even offers an existing interface to Qt widgets/C++ programs, it may only properly work in a QML application, possibly.

          1 Reply Last reply
          0
          • K Offline
            K Offline
            kehr_I
            wrote last edited by
            #5

            Ok, interesting. I didn't know, that QtCharts, which is still pretty new, will be replaced by QtGraphs.

            I've seen loads of QML examples. QML is - sadly - out of question for our application. Are there any examples on how to use it with QtWidgets only?

            JonBJ 1 Reply Last reply
            0
            • K kehr_I

              Ok, interesting. I didn't know, that QtCharts, which is still pretty new, will be replaced by QtGraphs.

              I've seen loads of QML examples. QML is - sadly - out of question for our application. Are there any examples on how to use it with QtWidgets only?

              JonBJ Online
              JonBJ Online
              JonB
              wrote last edited by
              #6

              @kehr_I
              You have my sympathies. QtCharts was a bit "dodgy" at times. Whether we like it or not it is going away, to be replaced by QtGraphs.

              I too have zero desire to use anything QML in my code (widgets). I believe it is "supposed" to be callable from widgets app --- presumably all QML/QtQuick stuff to support it will now have to be bundled with widgets app for deployment --- but I have a feeling there was a recent post saying the API "is not available"(?) from widgets, as of the present time at least. It might have said it works for 3D but not 2D. Ah, have a read of https://forum.qt.io/topic/159224/qt-graphs-building-2d-plot-using-c-only

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved