It seems to be the same old problem as has previously been discussed, that having the font makes the text lines thicker than 1px, which makes them polygons, which Qt struggles to draw. If I remove the font, it's fast again.
Turned off antialiasing on the element, made no difference.
Enabled OpenGL in QCP (which was a huge pain, messing with include paths in qcustomplot.h, and in the end having to remove the
glClear lines from
void QCPPaintBufferGlPbuffer::clear(const QColor &color) to quickly bypass unresolved externals just so I could see if it was worth bothering). And performance is far worse with OpenGL than without, so I've undone all those changes. I guess my problems with getting QCP to use OpenGL are a result of my combination of Qt6 and QCP2. After all, I did have to use this patch to get QCP2.1.0 to compile at all on Qt 6.2.4: https://www.qcustomplot.com/index.php/support/forum/2380 .
It just seems weird to me that replot can take over a second to run the very first time that a QCPTextElement with a font is added to the very first plot, but after that, adding and removing it from this plot or from any other plots in my application takes no time at all, and performance elsewhere in the app or elsewhere in the plot such as range dragging isn't affected by that element being there.
My workaround so far is to add it to a separate function which runs after the plot is constructed and plotted which is less intrusive to the user as at least they can see a plot without a title for the first second. And I guess I won't be having any fonts or lines within my plots thicker than 1px since my plots need to be interactive, which kinda sucks. Maybe I can take lines down to 1px and remove fonts during interactions and then make them pretty again afterwards. Haven't tried that yet. I might also make the title a QLabel outside of the plot.