PDA

View Full Version : QwtSvgPlotItem Proper Load Order



caggiadj
25th November 2019, 15:55
Hey Y'all,

What is the proper order to load an svg file then draw and attach it as a QwtSvgPlotItem onto a QwtPlot?

I am trying to draw a SVG to QwtPlot by using a QwtSvgPlotItem. I've loaded the SVG onto various QPainterDevices (QPixmap, QSvgRenderer, QIcon) and applied them onto QPainter without visual success each time. The file is properly loading and there are no errors, so it has to be in my procedure.Now I need to draw it, then attach it to the plot. Below is skeleton code of the order I have been working under should be done. Is it correct or is this backend developer missing something fundamental to frontend design?

QwtPlotSvgItem.loadFile(boundRect, svgAbsolutePath);
QPainter painter(&QPaintDevice);
planeSVG.draw(&painter, xScale, yScale, boundRect);
QwtPlotSvgItem.attach();

or

QwtPlotISvgItem.loadFile(boundRect, svgAbsolutePath);

QSvgRenderer renderer(svgAbsolutePath);
QPixmap pm(200,200);
QPainter painter(&pm);
renderer.render(&painter, pm.rect());
QwtPlotSvgItem.draw(&painter, xScale, yScale, boundRect);
QwtPlotSvgItem.attach();

Any insight is greatly appreciated

Sincerely,
Me

d_stranz
25th November 2019, 18:14
QwtPlotSvgItem.loadFile(boundRect, svgAbsolutePath);
QPainter painter(&QPaintDevice);
planeSVG.draw(&painter, xScale, yScale, boundRect);
QwtPlotSvgItem.attach();

What kind of code is this? It probably won't even compile, much less run and produce something useful.

Why don't you copy the -actual- code you are using instead of this barely pseudo-code?

caggiadj
25th November 2019, 18:53
The code compiles without a problem. My code intends to add PlotSvg capabilities to an already functional QwtPlot. The plot already supports other QwtPlotItems without problem.

I am inquiring about the integration of QwtSvgPlotItem, QtSvg, and QwtPlot altogether. I can only find examples of QtSvg. Thus all of my examples are built on stackoverflow examples, methods from books, and my own projects in QtCreator with me integrating in QwtPlot. Thus the code I posted is the closest correct procedurally I've developed thus far to my knowledge. I posted my code, just skeletoned down focused on the procedure.

d_stranz
25th November 2019, 21:47
I posted my code, just skeletoned down focused on the procedure.

Beg to differ.


QwtPlotSvgItem.loadFile(boundRect, svgAbsolutePath);

is not compilable C++ code. If it does in fact compile in your environment, then what is does is to:

1 - Create a temporary, default constructed QwtPlotSvgItem ("QwtPlotSvgItem.").
2 - Execute the loadFile() method on that temporary object.
3 - Destroy the temporary object at the end of the statement.

Net result is that absolutely nothing of consequence occurs.


QPainter painter(&QPaintDevice);

is quite simply nonsense.


planeSVG.draw(&painter, xScale, yScale, boundRect);

which implies that "planeSVG" is a stack-based temporary object ("." calling convention) which will be destroyed as soon as it goes out of scope, instead of a heap-based object ("->" calling convention) which will persist until explicitly deleted. So anything else the code does with this object will be undone when it leaves scope if it doesn't cause a segmentation fault before then.


QwtPlotSvgItem.attach();

Ditto the comments for the first statement.

If you really want some help, post the actual code for the entire method in which you are attempting to do this, so we can look for any obvious bugs and understand the context in which you are doing it.