Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please provide Qt-conform signals to make more interaction possible #4

Open
ArsMasiuk opened this issue Sep 3, 2020 · 1 comment
Open

Comments

@ArsMasiuk
Copy link

ArsMasiuk commented Sep 3, 2020

Hi!
I'm just curious how would it be possible to make Qt-application react on clicks on the chart items?

I.e. when I have a bar chart then I would like to intercept a click on bar's segment in my host Qt application, in order to obtain clicked bar's data (i.e. index and segment where the click has occurred).

There is submitEvent() function in Chart.qml, but how to use it from Qt code?
Thanks!

@ArsMasiuk
Copy link
Author

ArsMasiuk commented Sep 3, 2020

Well. Found a solution, maybe not the best one, but it works.
In order to fire itemClickedSignal, I've added to Chart.qml:

Canvas {
    id: root

....
// signal is sent when clicked on charts's item (i.e. barchart)
// itemIndex: index of the clicked bar in the dataset
// datasetIndex: index of the clicked bar's segment if any

signal itemClickedSignal(int itemIndex, int datasetIndex)

MouseArea {
...
        onClicked: {
            submitEvent(mouse, "click");

			var element = jsChart.getElementAtEvent(event.mouseEvent)[0];
			root.itemClickedSignal(element._index, element._datasetIndex);
        }
...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant