QCustomPlot Discussion and Comments

Adding new layer prevents interaction with graphsReturn to overview


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,



I could not find a way to work canonically (two layers, as described above). However, I now have kind of a workaround.

The plotsLayer is now the only one that I create above background, so that I see the grid.

I arrange myself to not allocate the text, lines, marker items in the base class, but I defer their creation the derived classes:

1. for trace (QCPGraph)-hosting widgets, I create the items at construction time, because the graph do not screen-off the items since they are so sparse.

2. for colormap (QCPColorMap)-hosting widgets (only one color map per plot widget), I create the items right after addition of the color map. Since the items are created *after* the color map, they render *after* that color map and are thus visible.

This is only a work around, because the whole idea of layers was to simplify this.

So, I am still eager to receive any advice or acknowledgement that this is bug. Hopefully fixed in the near future :-)

I forgot to mention the version of the lib: 2.0.1 (Debian testing box)


where is your interaction? some code?