Skip to content

Class QAccelPlot::PlotExporter

ClassList > QAccelPlot > PlotExporter

Exports a plot as a raster image: to a file, to the clipboard, or as a QImage .More...

  • #include <PlotExporter.hpp>

Inherits the following classes: QObject

Inheritance diagram

flowchart TB
  classQAccelPlot_1_1PlotExporter["QAccelPlot::PlotExporter"]

  external_base_classQAccelPlot_1_1PlotExporter_1["QObject"]
  external_base_classQAccelPlot_1_1PlotExporter_1 --> classQAccelPlot_1_1PlotExporter

Public Properties

Type Name
property bool busy
True from a request until its finished() signal.
property qreal dpi
Resolution stored in saved files, in dots per inch; 0 stores 96 times the effective scale. Default: 0.
property PlotView * plot
Plot to export; null once the plot is destroyed.
property int quality
Encoder quality from 0 to 100 passed to QImageWriter ; -1 uses the format's default. Default: -1.
property qreal scale
Image pixels per logical pixel; 0 uses the window's device pixel ratio. Default: 0.
property bool transparentBackground
Leaves out the plot's axesAreaColor andplotAreaColor backgrounds. Default: false.

Public Signals

Type Name
signal void busyChanged
Emitted when the busy property changes.
signal void dpiChanged
Emitted when the dpi property changes.
signal void finished (bool ok, const QString & path, const QString & error)
Emitted when a request ends; path is the saved file, empty for other requests.
signal void imageReady (const QImage & image)
Emitted with the captured image beforefinished() for agrabImage() request.
signal void plotChanged
Emitted when the plot property changes.
signal void qualityChanged
Emitted when the quality property changes.
signal void scaleChanged
Emitted when the scale property changes.
signal void transparentBackgroundChanged
Emitted when the transparentBackground property changes.

Public Functions

Type Name
PlotExporter (QObject * parent=nullptr)
Constructs an exporter without a plot.
PlotExporter (const PlotExporter &) = delete
PlotExporter (PlotExporter &&) = delete
bool busy () const
Returns true while a request is in progress.
Q_INVOKABLE bool copyToClipboard ()
Copies the plot image to the clipboard; returns false when the request fails immediately.
qreal dpi () const
Returns the resolution stored in saved files; 0 means 96 times the effective scale.
Q_INVOKABLE bool grabImage ()
Captures the plot and emits imageReady() ; returns false when the request fails immediately.
PlotExporter & operator= (const PlotExporter &) = delete
PlotExporter & operator= (PlotExporter &&) = delete
PlotView * plot () const
Returns the plot to export.
int quality () const
Returns the encoder quality.
Q_INVOKABLE bool save (const QString & path)
Saves the plot to path in the format its suffix names.
qreal scale () const
Returns the image pixels per logical pixel; 0 means the window's device pixel ratio.
void setDpi (qreal dpi)
Sets the stored resolution; negative and nonfinite values are ignored with a warning.
void setPlot (PlotView * plot)
Sets the plot to export; a request in progress keeps its plot.
void setQuality (int quality)
Sets the encoder quality; values outside -1 to 100 are ignored with a warning.
void setScale (qreal scale)
Sets the image pixels per logical pixel; negative and nonfinite values are ignored with a warning.
void setTransparentBackground (bool transparent)
Sets whether the image leaves out the plot's backgrounds.
bool transparentBackground () const
Returns whether the image leaves out the plot's backgrounds.
~PlotExporter () override
Restores the plot's appearance if a capture is in progress.

Public Static Functions

Type Name
Q_INVOKABLE QStringList supportedFormats ()
Returns the lowercase file suffixes save() accepts on this system, such aspng andjpg .

Detailed Description

The capture contains the plot item and everything drawn inside its bounds, as on screen: series, axes, legend, overlays, and any child items. Children outside the bounds are clipped. The plot must be visible in a window that is shown, not minimized, and renders through a hardware scene graph backend.

Every request is asynchronous and ends with exactly one finished() signal, except one made while busy: it returns false with a warning and leaves finished() to the request in progress. A request for a plot another exporter is capturing fails. The capture is taken on the next frame, and fails when the window is hidden, minimized, or destroyed first; encoding and writing a file run on a worker thread.

** **

PlotExporter {
    id: exporter
    plot: myPlot
    scale: 2
    onFinished: (ok, path, error) => console.log(ok ? "Saved " + path : error)
}
Button { text: "Save"; onClicked: exporter.save("plot.png") }

See also: PlotView

Public Properties Documentation

property busy

True from a request until its finished() signal.

bool QAccelPlot::PlotExporter::busy;


property dpi

Resolution stored in saved files, in dots per inch; 0 stores 96 times the effective scale. Default: 0.

qreal QAccelPlot::PlotExporter::dpi;

The default makes documents place the image at its on-screen size.


property plot

Plot to export; null once the plot is destroyed.

PlotView* QAccelPlot::PlotExporter::plot;


property quality

Encoder quality from 0 to 100 passed to QImageWriter ; -1 uses the format's default. Default: -1.

int QAccelPlot::PlotExporter::quality;

Lossy formats (JPEG, WebP) trade file size for artifacts. PNG stays lossless and only trades file size for encoding time. Other formats ignore it.


property scale

Image pixels per logical pixel; 0 uses the window's device pixel ratio. Default: 0.

qreal QAccelPlot::PlotExporter::scale;

At a device pixel ratio other than 1, Qt 6.3 and later cannot render every image size, so a side can be a pixel shorter or longer than the plot's size times the scale.


property transparentBackground

Leaves out the plot's axesAreaColor andplotAreaColor backgrounds. Default: false.

bool QAccelPlot::PlotExporter::transparentBackground;

Grid, series, axes, and child items such as the legend are drawn as usual. Formats without an alpha channel, such as JPEG, composite the image over white. The plot shows no background for the frame it is captured in.


Public Signals Documentation

signal busyChanged

Emitted when the busy property changes.

void QAccelPlot::PlotExporter::busyChanged;


signal dpiChanged

Emitted when the dpi property changes.

void QAccelPlot::PlotExporter::dpiChanged;


signal finished

Emitted when a request ends; path is the saved file, empty for other requests.

void QAccelPlot::PlotExporter::finished;

ok is false when the request failed, and error describes why.


signal imageReady

Emitted with the captured image beforefinished() for agrabImage() request.

void QAccelPlot::PlotExporter::imageReady;


signal plotChanged

Emitted when the plot property changes.

void QAccelPlot::PlotExporter::plotChanged;


signal qualityChanged

Emitted when the quality property changes.

void QAccelPlot::PlotExporter::qualityChanged;


signal scaleChanged

Emitted when the scale property changes.

void QAccelPlot::PlotExporter::scaleChanged;


signal transparentBackgroundChanged

Emitted when the transparentBackground property changes.

void QAccelPlot::PlotExporter::transparentBackgroundChanged;


Public Functions Documentation

function PlotExporter

Constructs an exporter without a plot.

explicit QAccelPlot::PlotExporter::PlotExporter (
    QObject * parent=nullptr
) 


function PlotExporter

QAccelPlot::PlotExporter::PlotExporter (
    const PlotExporter &
) = delete

function PlotExporter

QAccelPlot::PlotExporter::PlotExporter (
    PlotExporter &&
) = delete

function busy

Returns true while a request is in progress.

bool QAccelPlot::PlotExporter::busy () const


function copyToClipboard

Copies the plot image to the clipboard; returns false when the request fails immediately.

Q_INVOKABLE bool QAccelPlot::PlotExporter::copyToClipboard () 


function dpi

Returns the resolution stored in saved files; 0 means 96 times the effective scale.

qreal QAccelPlot::PlotExporter::dpi () const


function grabImage

Captures the plot and emits imageReady() ; returns false when the request fails immediately.

Q_INVOKABLE bool QAccelPlot::PlotExporter::grabImage () 


function operator=

PlotExporter & QAccelPlot::PlotExporter::operator= (
    const PlotExporter &
) = delete

function operator=

PlotExporter & QAccelPlot::PlotExporter::operator= (
    PlotExporter &&
) = delete

function plot

Returns the plot to export.

PlotView * QAccelPlot::PlotExporter::plot () const


function quality

Returns the encoder quality.

int QAccelPlot::PlotExporter::quality () const


function save

Saves the plot to path in the format its suffix names.

Q_INVOKABLE bool QAccelPlot::PlotExporter::save (
    const QString & path
) 

path may be a local file path or a file: URL. An existing file is replaced only when the new one is written completely. Returns false when the request fails immediately, after emitting finished() unless the exporter is busy.


function scale

Returns the image pixels per logical pixel; 0 means the window's device pixel ratio.

qreal QAccelPlot::PlotExporter::scale () const


function setDpi

Sets the stored resolution; negative and nonfinite values are ignored with a warning.

void QAccelPlot::PlotExporter::setDpi (
    qreal dpi
) 


function setPlot

Sets the plot to export; a request in progress keeps its plot.

void QAccelPlot::PlotExporter::setPlot (
    PlotView * plot
) 


function setQuality

Sets the encoder quality; values outside -1 to 100 are ignored with a warning.

void QAccelPlot::PlotExporter::setQuality (
    int quality
) 


function setScale

Sets the image pixels per logical pixel; negative and nonfinite values are ignored with a warning.

void QAccelPlot::PlotExporter::setScale (
    qreal scale
) 


function setTransparentBackground

Sets whether the image leaves out the plot's backgrounds.

void QAccelPlot::PlotExporter::setTransparentBackground (
    bool transparent
) 


function transparentBackground

Returns whether the image leaves out the plot's backgrounds.

bool QAccelPlot::PlotExporter::transparentBackground () const


function ~PlotExporter

Restores the plot's appearance if a capture is in progress.

QAccelPlot::PlotExporter::~PlotExporter () override


Public Static Functions Documentation

function supportedFormats

Returns the lowercase file suffixes save() accepts on this system, such aspng andjpg .

static Q_INVOKABLE QStringList QAccelPlot::PlotExporter::supportedFormats () 



The documentation for this class was generated from the following file QAccelPlot/src/QAccelPlot/export/PlotExporter.hpp