Results 1 to 7 of 7

Thread: Insert SVG inside QTextDocument

  1. #1
    Join Date
    May 2008
    Posts
    276
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Insert SVG inside QTextDocument

    Sorry to re-post the same problem.
    I have a QTextDocument which I fill with some tables and data.
    I created the QwtPlot of these data and I would like too insert the plot inside the QTextDocument. Eventually, I would print the pdf version of the document.
    I choose SVG because it can render with high and beutiful resolution.
    But, how can insert the svg graphics inside the QTextDocument and then print it on QPrinter?
    regards

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Insert SVG inside QTextDocument

    Can QwtPlot render its vector based representation to SVG or only its bitmap SVG representation? Because if the latter, using SVG will have no positive influence on the result. I don't think there is any way to place an SVG file to a text document but if you have the size of the document, you can render the svg of the required size to png and insert the image into the document.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    May 2008
    Posts
    276
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Insert SVG inside QTextDocument

    Qwtplot can render on any paintdevice.
    For example, when I save my plot on disk, I use print(svggenerator,filter), where svggenerator is a QSvgGenerator.
    I can use png, but in that case the resolution will be not so high.
    G

  4. #4
    Join Date
    May 2008
    Posts
    276
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Insert SVG inside QTextDocument

    Now I am trying this:
    Qt Code:
    1. m_document->print(&printer);
    2.  
    3.  
    4. int options = QwtPlotPrintFilter::PrintAll;
    5. options &= ~QwtPlotPrintFilter::PrintBackground;
    6. options |= QwtPlotPrintFilter::PrintFrameWithScales;
    7. filter.setOptions(options);
    8. printer.newPage();
    9. solarDiagram->print(printer,filter);
    To copy to clipboard, switch view to plain text mode 
    where solarDiagram is the pointer to a QwtPlot.
    But as you can imagine, the print contains only the plot and not the textdocument.
    Thereis a way to tell QTextDocument to "paint" on printer?
    Or, how can I bind two printing on the same QPrinter?

  5. #5
    Join Date
    May 2008
    Posts
    276
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Insert SVG inside QTextDocument

    Now I am trying this:
    Qt Code:
    1. m_document->print(&printer);
    2.  
    3.  
    4. int options = QwtPlotPrintFilter::PrintAll;
    5. options &= ~QwtPlotPrintFilter::PrintBackground;
    6. options |= QwtPlotPrintFilter::PrintFrameWithScales;
    7. filter.setOptions(options);
    8. printer.newPage();
    9. solarDiagram->print(printer,filter);
    To copy to clipboard, switch view to plain text mode 
    where solarDiagram is the pointer to a QwtPlot.
    But as you can imagine, the print contains only the plot and not the textdocument.
    Thereis a way to tell QTextDocument to "paint" on printer?
    Or, how can I bind two printing on the same QPrinter?

    I tried the followind code
    Qt Code:
    1. QPrinter printer(QPrinter::HighResolution);
    2. m_document->setPageSize(printer.pageRect().size());
    3.  
    4.  
    5. printer.setOutputFileName(fileName);
    6. ....
    7.  
    8. p.begin(&printer);
    9. m_document->drawContents(&p,printer.paperRect());
    10. printer.newPage();
    11. solarDiagram->print(&p,printer.paperRect(),filter);
    12. p.end();
    To copy to clipboard, switch view to plain text mode 
    but the textdocument is too small to be seen in the pdf printout, and the plot is printed in the correct size and with high resolution (pdf).
    Why the textdocument is not rendered in the correct size?

  6. #6
    Join Date
    May 2008
    Posts
    276
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Insert SVG inside QTextDocument

    I found this solution


    Qt Code:
    1. QPrinter printer(QPrinter::HighResolution);
    2. ...
    3. int pw = printer.pageRect().width();
    4. int ph =printer.pageRect().height();
    5.  
    6. p.begin(&printer);
    7.  
    8. p.save();
    9. m_document->adjustSize();
    10. QTransform tra;
    11. tra.scale(11,11);
    12. p.setTransform(tra);
    13.  
    14. m_document->drawContents(&p,printer.paperRect());
    15.  
    16.  
    17. p.restore();
    18. QRect rec(-10,0,pw-10,0.4*ph);
    19. p.translate(0,0.65*ph);
    20. solarDiagram->print(&p,rec,filter);
    21. p.end();
    To copy to clipboard, switch view to plain text mode 
    This is good for A4 paper. The plot is rendered as a vector graphic and I like it.
    But I would scale the painter automatically. The value "11" is taken from a trial-and-correct approach....

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Insert SVG inside QTextDocument

    Compare the size of the painter to the size of the device or use QPainter::setWindow() and QPainter::setViewport()
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Insert SVG file into QtextDocument
    By giusepped in forum Qt Programming
    Replies: 1
    Last Post: 14th April 2009, 04:15
  2. Drawing QImage inside QTextDocument
    By giusepped in forum Qt Programming
    Replies: 0
    Last Post: 13th April 2009, 07:52
  3. Insert QwtPlot in QTextDocument
    By giusepped in forum Qwt
    Replies: 1
    Last Post: 9th April 2009, 09:51
  4. [Qt4.1] How to insert an image inside a Form?
    By Gonzalez in forum Qt Tools
    Replies: 5
    Last Post: 23rd September 2008, 11:20
  5. SQL QThread how i can insert a lock?
    By patrik08 in forum Qt Programming
    Replies: 3
    Last Post: 12th June 2007, 00:12

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.