Results 1 to 4 of 4

Thread: QwtSvgPlotItem Proper Load Order

  1. #1
    Join Date
    Nov 2019
    Posts
    4
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default QwtSvgPlotItem Proper Load Order

    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
    Last edited by caggiadj; 25th November 2019 at 17:02.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,240
    Thanks
    239
    Thanked 672 Times in 662 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: QwtSvgPlotItem Proper Load Order

    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?
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Nov 2019
    Posts
    4
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QwtSvgPlotItem Proper Load Order

    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.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,240
    Thanks
    239
    Thanked 672 Times in 662 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: QwtSvgPlotItem Proper Load Order

    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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Replies: 6
    Last Post: 4th March 2013, 21:20
  2. Replies: 3
    Last Post: 28th September 2012, 15:01
  3. Proper way to use qmake and moc?
    By mossen in forum Newbie
    Replies: 1
    Last Post: 6th May 2011, 03:52
  4. [4.7] QML properties load order
    By bunjee in forum Qt Programming
    Replies: 0
    Last Post: 25th September 2010, 00:45
  5. Proper way to #include Qt?
    By pherthyl in forum Qt Programming
    Replies: 1
    Last Post: 11th August 2006, 03:15

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.