QCustomPlot Discussion and Comments

Semi-cosmetic ellipseReturn to overview

Hello. I want to have ellipse with fixed size in pixels, so when you zoom plot, it's center stays at same coordinates, while visible (pixel) size is keeped unchaged.

What's best way to do that?

(it should keep it's size either on zoom and on widget resize)

in Position() method of ellipse use setType() method to change positioning type. see:

But what position I need? It has positions only for top left and bottom right corners.

If you want the position of the ellipse follow plot coordinates but be sized in static pixels, you'll have to place the ellipse as a child of another item which is anchored in plot coordinates. E.g. like this:
Create a QCPItemTracer and set its style with setStyle to QCPItemTracer::tsNone. This way the QCPItemTracer will just serve as an invisible position that we can use as parent to the ellipse. Set the QCPItemTracer position to be at the desired plot coordinates.
Now you set the ellipse's position to be the child of the tracer's position with


now the coordinates of the topLeft and bottomRight positions of the ellipse are relative in pixels to the tracer position. So if you want the ellipse centered on the tracer, you could set the ellipse's position like this:

ellipse->topLeft->setCoords(-5, -5);
ellipse->bottomRight->setCoords(5, 5);

The ellipse will then be 10*10 pixels in size.

Thank you very much! This example should go to Documentation i guess.