How to find which axis has been clicked on a QChartView
-
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 asreturn 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.
-
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 asreturn 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.
-
@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?@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...
-
@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...
@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.
-
-
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?
@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