I'm still new with qcustomplot and trying to understand the interaction functionality. I studied the interaction example and wanted to adapt it a little bit to my needs. I'd like to be able to open a context menu on an item in the legend and/or on any graph in the plot. Unfortunately I couldn't find out yet how to accomplish this.
I understood that in
mainwindow.cpp, line 56, this connect statement ...
connect(ui->customPlot, SIGNAL(customContextMenuRequested(QPoint)), this, SLOT(contextMenuRequest(QPoint)));
... together with the slot method
contextMenuRequest(QPoint) manages the creation of a context menu when the cursor is placed on the legend and then a secondary click is issued. In the above mentioned method the menu is created and populated with actions to move the legend. In case a legend item was at the cursor position when the secondary click was issued I want to add a menu entry which shows a popup window that allow for editing some properties of the respective graph.
So in the
contextMenuRequest() method I need to be able to
1. determine which graph's legend item was below the cursor and
2. pass this information to the menu action that brings up the editing window for
For step 1. I tried this (in the method
contextMenuRequest() at line 234):
auto legendItem = qobject_cast<QCPAbstractLegendItem*>(itemAt(pos));
But unfortunately the call to
itemAt(pos) always returns 0. What am I doing wrong?