I have studied the problem of layer ordering a lot (docs and this forum). I tried to fix my code in manners matching recommendations found in various topics in this forum. To no avail. So let me describe my setting.
1. Allocate new QCustomPlot-derived class.
2. In the constructor create two new layers: plotsLayer (above background) and ancillaryItemsLayer (above plotsLayer), such that the layers are like this:
All layer names:
Layer index 0: background
Layer index 1: plotsLayer
Layer index 2: ancillaryItemsLayer
Layer index 3: grid
Layer index 4: main
Layer index 5: axes
Layer index 6: legend
Layer index 7: overlay
In that same constructor I allocate a number of items that will be updated during operation of the plot, like four lines that delimit a selection rectangle (home-written because of some geometrical constraints), some text items describing numerical variable and so on.
Note, that for each new item (allocated on the heap), I call setLayer() like this:
3. During operation of the plot, the user might create as many QCPGraph instances as necessary to be stuffed in the same QCustomPlot-derived instance or one (and only one) QCPColorMap to be in a QCustomPlot-derived instance.
4. With this setting, everything looks fine beause I see that the tracers and markers actually overdraw the plots (graph or color map). Very cool.
5. Point is: when I organize that setup, I loose the ability to select graphs (which I need badly).
6. The other way I tried, but that is not working from a layer-ordering standpoint, is to stuff everything in the default "main" layer. In that case, I can select graphs, BUT I loose the visibility of the tracers and text items when the plot is a color map. I can still see them in the plot where only graphs are plotted because the plot area is not opaque.
One idea would be to still stuff everything on the "main" layer and control the Z-ordering of the various elements. For example, is it possible, after each addition of a plot (graph or color map) to force it below the other items in the *same* layer ? I understand from the documentation that the order with which the items are rendered in a layer is the order in which they were created. In my case, this would not work, because all the markers, lines, rectangle, text items are allocate at plot construction time well before the plot is populated with graphs and color maps.
What I am missing here ?
Thanks for reading up to here,