Exporting graphs
Graphs can be exported in two types of formats:
Screen capture
The quickest and most accurate export method is to use Item::grabToImage. This method will export any visible Items with pixel-perfect accuracy. However, since it works by grabbing data from the rendering backend, it can only export a raster image, and only if it is part of a scene. This method cannot export vector files, or non-visible parts of graphs.
For documentation and examples, consult the Qt docs at Item::grabToImage.
QPainter-based export
QuickGraphLib has it's own export methods which support a wider range of export formats, but do not support all Item types and will not be pixel-perfect:
- Helpers::exportToPng, for PNG (raster) export
- Helpers::exportToSvg, for SVG (vector) export
- Helpers::exportToPicture, for export to a QPicture (vector)
These methods iterate though the Item tree for a given Item, and attempt to draw each Item using a QPainter. Since each Item is converted into a series of vector drawing commands, these methods can export in both raster and vector formats. However, these methods have corresponding downsides:
- Any Item types not handled by QuickGraphLib cannot be exported - they will simply not appear in the exported file
- Not all properties of supported Item types are supported
If an element is not rendered correctly, create a new issue on GitHub and we'll see if it can be supported.
Known issues
- Rectangle items must have border.width set to zero if the border should be hidden. This is because the border width defaults to 1, and there is no public API for checking if the width or color has been set.