### Multi-Graph Plot with Styling in QCustomPlot Source: https://context7.com/ecme2/qcustomplot/llms.txt Illustrates how to create a plot with multiple graphs, each having distinct visual styles (pens and brushes). It includes generating data for two different functions, assigning them to graphs, and rescaling axes. This example requires Qt and QCustomPlot. ```cpp QCustomPlot *customPlot = new QCustomPlot(); // Add two graphs with different styles customPlot->addGraph(); customPlot->graph(0)->setPen(QPen(Qt::blue)); customPlot->graph(0)->setBrush(QBrush(QColor(0, 0, 255, 20))); // translucent fill customPlot->addGraph(); customPlot->graph(1)->setPen(QPen(Qt::red)); // Generate data QVector x(251), y0(251), y1(251); for (int i=0; i<251; ++i) { x[i] = i; y0[i] = qExp(-i/150.0)*qCos(i/10.0); // damped cosine y1[i] = qExp(-i/150.0); // exponential envelope } // Set data and rescale axes customPlot->graph(0)->setData(x, y0); customPlot->graph(1)->setData(x, y1); customPlot->graph(0)->rescaleAxes(); customPlot->graph(1)->rescaleAxes(true); // true = only enlarge ranges customPlot->replot(); ``` -------------------------------- ### Non-Zero Base Values for QCPBars Source: https://gitlab.com/ecme2/qcustomplot/-/blob/master/changelog.txt QCPBars now supports non-zero base values through the `setBaseValue` property. This allows for more flexible bar chart visualizations where bars do not necessarily start from zero. Requires QCPBars and QCustomPlot. ```cpp // Example of setting a non-zero base value // QCPBars *bars = new QCPBars(customPlot->xAxisRect()); // bars->setBaseValue(10.0); // Bars will start from 10.0 ``` -------------------------------- ### Optimize Graph Rendering: Line Width and Fills Source: https://gitlab.com/ecme2/qcustomplot/-/blob/master/src/doc-performance.dox Recommendations for optimizing graph rendering performance. Avoid using pen widths greater than one and complex fills, especially with the default software renderer. OpenGL acceleration mitigates some of these performance impacts. ```cpp // Avoid lines with pen width > 1 // Avoid complex fills (e.g., channel fills with many points) ``` -------------------------------- ### Implement Real-Time Data Plotting in QCustomPlot Source: https://context7.com/ecme2/qcustomplot/llms.txt This example outlines the approach for real-time data plotting in QCustomPlot. It involves adding data points incrementally and updating the axis ranges to create a scrolling effect. This typically requires integration with a timer (e.g., QTimer) for periodic updates. Dependencies include QCustomPlot and Qt modules. ```cpp QCustomPlot *customPlot = new QCustomPlot(); customPlot->addGraph(); customPlot->graph(0)->setPen(QPen(Qt::blue)); // Configure for real-time display customPlot->xAxis->setLabel("Time"); customPlot->yAxis->setLabel("Value"); customPlot->xAxis->setRange(0, 100); customPlot->yAxis->setRange(-1, 1); // In a timer slot or update function: // void updatePlot() // { // static double lastPointKey = 0; // double key = lastPointKey + 1; // double value = qSin(key/10.0); // // // Add data point // customPlot->graph(0)->addData(key, value); // // // Remove old data outside visible range // customPlot->graph(0)->data()->removeBefore(key - 100); // // // Scroll axis range // customPlot->xAxis->setRange(key, 100, Qt::AlignRight); // // customPlot->replot(); // lastPointKey = key; // } // Connect to QTimer for periodic updates: // QTimer *dataTimer = new QTimer(this); // connect(dataTimer, &QTimer::timeout, this, &MainWindow::updatePlot); // dataTimer->start(50); // update every 50ms ``` -------------------------------- ### Efficiently Add Data to QCustomPlot Graphs Source: https://gitlab.com/ecme2/qcustomplot/-/blob/master/src/doc-performance.dox Recommends using `QCPGraph::addData` instead of repeatedly calling `QCPGraph::setData` when most data points remain unchanged, such as in real-time measurements. This approach is more efficient for updating existing datasets. ```cpp // Instead of: // graph->setData(newKey, newValue); // Use addData for incremental updates: graph->addData(key, value); // To manipulate existing data: // QCPGraphDataMap *dataMap = graph->data(); // dataMap->at(index)->key = newKey; // dataMap->at(index)->value = newValue; ``` -------------------------------- ### Qt4 Specific Performance: Graphics System Selection Source: https://gitlab.com/ecme2/qcustomplot/-/blob/master/src/doc-performance.dox For Qt4 on X11 (GNU/Linux), using the 'raster' graphics system can significantly improve performance compared to the native drawing system. This is achieved either via command-line argument or by calling `QApplication::setGraphicsSystem`. ```cpp // Via command line: // ./your_application -graphicssystem raster // Or in code before creating QApplication: // QApplication::setGraphicsSystem("raster"); ``` -------------------------------- ### Configure Multi-Axis Plot in QCustomPlot Source: https://context7.com/ecme2/qcustomplot/llms.txt This example demonstrates how to create a QCustomPlot with multiple independent y-axes. It adds a second y-axis to the right of the plot and assigns a separate graph to it, allowing for visualization of data with different scales. Requires QCustomPlot and Qt modules. ```cpp QCustomPlot *customPlot = new QCustomPlot(); // Add first graph on left y-axis customPlot->addGraph(customPlot->xAxis, customPlot->yAxis); customPlot->graph(0)->setPen(QPen(Qt::blue)); customPlot->graph(0)->setName("Left Axis Data"); // Add second axis on the right customPlot->axisRect()->addAxis(QCPAxis::atRight); customPlot->axisRect()->axis(QCPAxis::atRight, 0)->setPen(QPen(Qt::red)); customPlot->axisRect()->axis(QCPAxis::atRight, 0)->setTickLabelColor(Qt::red); // Add second graph on right y-axis customPlot->addGraph(customPlot->xAxis, customPlot->axisRect()->axis(QCPAxis::atRight, 0)); customPlot->graph(1)->setPen(QPen(Qt::red)); customPlot->graph(1)->setName("Right Axis Data"); // Generate data for both graphs QVector x(100), y1(100), y2(100); for (int i=0; i<100; ++i) { x[i] = i; y1[i] = qSin(i/10.0); // range: -1 to 1 y2[i] = qExp(i/50.0); // exponential growth } customPlot->graph(0)->setData(x, y1); customPlot->graph(1)->setData(x, y2); customPlot->graph(0)->rescaleAxes(); customPlot->graph(1)->rescaleAxes(); customPlot->legend->setVisible(true); customPlot->replot(); ``` -------------------------------- ### QCustomPlot Performance Tips: Transparency and Antialiasing Source: https://gitlab.com/ecme2/qcustomplot/-/blob/master/src/doc-performance.dox General advice for optimizing QCustomplot rendering. Avoid using transparency (alpha colors) in fills and disable antialiasing, especially for graph lines, when using the default software renderer. For OpenGL, antialiasing behavior differs. ```cpp // Avoid alpha (transparency) colors in fills. // Avoid antialiasing, especially in graph lines: // customPlot->setNotAntialiasedElements(QCP::antialiasedElements); // (Note: Call with appropriate flags to enable/disable) ``` -------------------------------- ### Enable OpenGL Hardware Acceleration in QCustomPlot Source: https://gitlab.com/ecme2/qcustomplot/-/blob/master/src/doc-performance.dox Enables hardware-accelerated rendering for QCustomPlot graphs to improve performance, particularly with complex fills and thick lines. This method is available for all supported Qt versions. For Qt versions before 5.0, alternative methods using QApplication::setGraphicsSystem are also mentioned. ```cpp /// Enable QCustomPlot's OpenGL acceleration: customPlot->setOpenGl(true); /// For Qt versions before 5.0 (alternative): // QApplication::setGraphicsSystem("opengl"); ``` -------------------------------- ### Create Simple Line Graph with QCustomPlot Source: https://context7.com/ecme2/qcustomplot/llms.txt Demonstrates how to create a simple line graph using QCustomPlot. It involves generating data points, adding a graph, setting data, configuring axes, and replotting. Requires the QCustomPlot header and C++11. ```cpp #include "qcustomplot.h" QCustomPlot *customPlot = new QCustomPlot(); // Generate data QVector x(101), y(101); for (int i=0; i<101; ++i) { x[i] = i/50.0 - 1; // x ranges from -1 to 1 y[i] = x[i]*x[i]; // quadratic function } // Create graph and assign data customPlot->addGraph(); customPlot->graph(0)->setData(x, y); // Configure axes customPlot->xAxis->setLabel("x"); customPlot->yAxis->setLabel("y"); customPlot->xAxis->setRange(-1, 1); customPlot->yAxis->setRange(0, 1); // Render the plot customPlot->replot(); ``` -------------------------------- ### Disable Antialiasing on Drag for QCustomPlot Source: https://gitlab.com/ecme2/qcustomplot/-/blob/master/src/doc-performance.dox Increases responsiveness during range dragging by disabling antialiasing. This is primarily relevant for the default software renderer, as OpenGL antialiasing cannot be toggled on-the-fly without buffer reallocation. ```cpp customPlot->setNoAntialiasingOnDrag(true); ``` -------------------------------- ### Immediate or Queued Repaint with QCustomPlot::replot Source: https://gitlab.com/ecme2/qcustomplot/-/blob/master/changelog.txt The `QCustomPlot::replot` method now allows specifying whether the widget update should be immediate (repaint) or queued (update). This provides control over rendering behavior. Requires `QCustomPlot`. ```cpp // Replotting with immediate update // customPlot->replot(true); // True for immediate repaint ``` -------------------------------- ### 2D Color Maps with QCPColorMap and QCPColorScale Source: https://gitlab.com/ecme2/qcustomplot/-/blob/master/changelog.txt Introduces the `QCPColorMap` plottable and `QCPColorScale` layout element for plotting 2D color maps. This enables visualization of data distributions or scalar fields. Requires `QCPColorMap`, `QCPColorScale`, and `QCustomPlot`. ```cpp // Example of adding a color map // QCPColorMap *colorMap = new QCPColorMap(customPlot->xAxisRect()); // customPlot->addPlottable(colorMap); // colorMap->setData(...); // Set 2D data // QCPColorScale *colorScale = new QCPColorScale(customPlot); // customPlot->plotLayout()->addElement(0, 1, colorScale); ``` -------------------------------- ### Compatibility with Qt Macros Source: https://gitlab.com/ecme2/qcustomplot/-/blob/master/changelog.txt Code has been made compatible with `QT_NO_CAST_FROM_ASCII` and `QT_NO_CAST_TO_ASCII`. This ensures broader compatibility with different Qt build configurations. No specific code snippet is required as it's a build-time compatibility change. -------------------------------- ### Set Opaque Paint Event Attribute for QCustomPlot Source: https://gitlab.com/ecme2/qcustomplot/-/blob/master/src/doc-performance.dox Applies the `Qt::WA_OpaquePaintEvent` attribute to the QCustomPlot widget, potentially saving a fill operation during each paint event. Note that this might affect how the widget is grayed out with modal dialogs on embedded systems. ```cpp customPlot->setAttribute(Qt::WA_OpaquePaintEvent); ``` -------------------------------- ### Create and Configure QCPCurve in C++ Source: https://gitlab.com/ecme2/qcustomplot/-/blob/master/src/doc-mainpage.dox Demonstrates the creation of a QCPCurve plottable and subsequent access to its properties via a pointer. This method is used for plottables other than QCPGraph. It involves creating an instance, adding it to the plot, and then manipulating its properties through the returned pointer. ```cpp QCPCurve *newCurve = new QCPCurve(customPlot->xAxis, customPlot->yAxis); customPlot->addPlottable(newCurve); newCurve->setName("My Curve"); // ... set data and other properties ``` -------------------------------- ### Limit Visible Data Points in QCustomPlot Source: https://gitlab.com/ecme2/qcustomplot/-/blob/master/src/doc-performance.dox As a final optimization step, reduce the number of data points within the visible key range. This can be achieved by limiting the maximum key range span, allowing QCustomPlot to efficiently discard off-screen points. ```cpp // Example using the rangeChanged signal to limit the span: // connect(customPlot->xAxis, SIGNAL(rangeChanged(QCPRange)), this, SLOT(xAxisRangeChanged(QCPRange))); // private slots: // void xAxisRangeChanged(const QCPRange &newRange) { // double maxSpan = 1000.0; // Example maximum span // if (newRange.size() > maxSpan) { // customPlot->xAxis->setRange(newRange.center(), maxSpan); // } // } ``` -------------------------------- ### Range Operators and Comparison Source: https://gitlab.com/ecme2/qcustomplot/-/blob/master/changelog.txt The `QCPRange` class now supports operators `+`, `-`, `*`, `/` with a double operand for range shifting and scaling. It also includes `==` and `!=` for range comparison. Requires `QCPRange`. ```cpp // Range operations // QCPRange range(0, 10); // QCPRange shiftedRange = range + 5; // QCPRange scaledRange = range * 2; // bool isEqual = (range == QCPRange(0, 10)); ``` -------------------------------- ### Adaptive Sampling for QCPGraph Performance Source: https://gitlab.com/ecme2/qcustomplot/-/blob/master/changelog.txt QCPGraph now features adaptive sampling, significantly improving performance for plots with high data densities. This is enabled via `QCPGraph::setAdaptiveSampling`. Requires `QCPGraph` and `QCustomPlot`. ```cpp // Enabling adaptive sampling // QCPGraph *graph = customPlot->addGraph(); // graph->setAdaptiveSampling(true); // graph->setData(...); ``` -------------------------------- ### Axis Convenience Functions Source: https://gitlab.com/ecme2/qcustomplot/-/blob/master/changelog.txt Static functions `QCPAxis::opposite` and `QCPAxis::orientation` provide more convenience when handling different axis types. These functions simplify axis management. Requires `QCPAxis`. ```cpp // Example usage (conceptual) // QCPAxis *axis1 = ...; // QCPAxis *oppositeAxis = QCPAxis::opposite(axis1); // QCPAxis::Orientation orientation = QCPAxis::orientation(axis1); ``` -------------------------------- ### QCustomPlot Performance Optimization Techniques (C++) Source: https://context7.com/ecme2/qcustomplot/llms.txt Demonstrates C++ code for optimizing QCustomPlot performance. It includes disabling antialiasing during drag, enabling OpenGL acceleration, using adaptive sampling for large datasets, setting plotting hints for faster rendering, employing queued replot for batch updates, and applying data decimation for extremely large datasets. ```cpp QCustomPlot *customPlot = new QCustomPlot(); // Disable antialiasing during drag for better performance customPlot->setNoAntialiasingOnDrag(true); // Enable OpenGL for hardware acceleration customPlot->setOpenGl(true, 16); // 16 = multisampling level // Use adaptive sampling for large datasets customPlot->addGraph(); customPlot->graph(0)->setAdaptiveSampling(true); // Set plotting hints for optimization customPlot->setPlottingHints(QCP::phFastPolylines | QCP::phImmediateRefresh); // Use queued replot to batch multiple changes customPlot->replot(QCustomPlot::rpQueuedReplot); // For very large datasets, use data decimation QVector x(1000000), y(1000000); // ... fill data ... // Only plot every Nth point for distant zoom levels customPlot->graph(0)->setLineStyle(QCPGraph::lsLine); customPlot->graph(0)->setScatterSkip(10); // skip 10 points between scatter symbols ``` -------------------------------- ### Use Buffered Layers for Dynamic QCustomPlot Objects Source: https://gitlab.com/ecme2/qcustomplot/-/blob/master/src/doc-performance.dox Improves performance when frequently updating non-complex objects (like items) while having static complex graphs. By placing dynamic objects on a separate layer set to `lmBuffered` mode, QCustomPlot allocates a dedicated paint buffer, allowing individual replotting without affecting other layers. ```cpp /// Assuming 'myLayer' is a QCPLayer object myLayer->setMode(QCPLayer::lmBuffered); /// Replot the specific layer if needed: // myLayer->replot(); ``` -------------------------------- ### Displaying Gaps in QCPGraph/QCPCurve Lines Source: https://gitlab.com/ecme2/qcustomplot/-/blob/master/changelog.txt QCPGraph and QCPCurve can now display gaps in their lines when quiet NaN values are inserted. This improves the visualization of missing data points. Requires QCPGraph/QCPCurve and QCustomPlot. ```cpp // Inserting NaN to create a gap // QVector x, y; // ... // y.append(std::numeric_limits::quiet_NaN()); // Creates a gap // customPlot->graph(0)->setData(x, y); ``` -------------------------------- ### Create Financial Charts (Candlestick/OHLC) with C++ Source: https://context7.com/ecme2/qcustomplot/llms.txt Creates candlestick and OHLC charts for financial data using QCPFinancial. It generates time-series data, configures the candlestick style, and sets up a date/time axis. Dependencies include QCustomPlot, Qt, and C++ STL. Inputs are time and value series, outputs are financial charts. ```cpp QCustomPlot *customPlot = new QCustomPlot(); // Generate time series data int n = 500; QVector time(n), value(n); QDateTime start(QDate(2014, 6, 11), QTime(0, 0)); start.setTimeSpec(Qt::UTC); double startTime = start.toMSecsSinceEpoch()/1000.0; double binSize = 3600*24; // 1 day intervals time[0] = startTime; value[0] = 60; for (int i=1; ixAxis, customPlot->yAxis); candlesticks->setName("Candlestick"); candlesticks->setChartStyle(QCPFinancial::csCandlestick); candlesticks->data()->set(QCPFinancial::timeSeriesToOhlc(time, value, binSize, startTime)); candlesticks->setWidth(binSize*0.9); candlesticks->setTwoColored(true); candlesticks->setBrushPositive(QColor(245, 245, 245)); candlesticks->setBrushNegative(QColor(40, 40, 40)); candlesticks->setPenPositive(QPen(QColor(0, 0, 0))); candlesticks->setPenNegative(QPen(QColor(0, 0, 0))); // Configure date/time axis QSharedPointer dateTimeTicker(new QCPAxisTickerDateTime); dateTimeTicker->setDateTimeSpec(Qt::UTC); dateTimeTicker->setDateTimeFormat("dd. MMMM"); customPlot->xAxis->setTicker(dateTimeTicker); customPlot->xAxis->setTickLabelRotation(15); customPlot->legend->setVisible(true); customPlot->rescaleAxes(); customPlot->replot(); ``` -------------------------------- ### Qt4 Performance Improvement with Newer Qt Versions Source: https://gitlab.com/ecme2/qcustomplot/-/blob/master/src/doc-performance.dox Utilizing Qt 4.8 or newer provides a significant performance boost (two to three times faster) compared to Qt 4.7. However, be aware that Qt 4.8 has drawing inaccuracies for pixel-precise elements like scatters, presenting a trade-off between performance and plot quality. ```cpp // Ensure you are using Qt 4.8 or a later version for performance gains. // Be mindful of potential visual differences in pixel-precise rendering. ``` -------------------------------- ### Injecting Custom Axes with QCPAxisRect Source: https://gitlab.com/ecme2/qcustomplot/-/blob/master/changelog.txt Allows injecting custom `QCPAxis` (or subclasses) via the second optional parameter of `QCPAxisRect::addAxis`. This provides flexibility in customizing axis behavior. Requires `QCPAxisRect` and `QCustomPlot`. ```cpp // Injecting a custom axis // class MyCustomAxis : public QCPAxis { ... }; // QCPAxisRect *rect = customPlot->axisRect(); // MyCustomAxis *customAxis = new MyCustomAxis(rect, QCPAxis::atBottom); // rect->addAxis(customAxis, QCP::atBottom); ``` -------------------------------- ### Financial Data Display with QCPFinancial Source: https://gitlab.com/ecme2/qcustomplot/-/blob/master/changelog.txt Introduces the QCPFinancial class for displaying candlestick and OHLC data. This new plottable type enhances financial charting capabilities within QCustomPlot. Requires Qt and QCustomPlot library. ```cpp // Example usage of QCPFinancial (conceptual) // QCPFinancial *candlestickPlot = new QCPFinancial(customPlot->axisRect()); // customPlot->addPlottable(candlestickPlot); // candlestickPlot->setData(...); // Set OHLC data ``` -------------------------------- ### Create Color Map for 2D Data Visualization with C++ Source: https://context7.com/ecme2/qcustomplot/llms.txt Generates a heatmap from 2D data using QCPColorMap. It sets up the data range, fills cells with calculated values, adds a color scale, and applies a gradient. Dependencies include QCustomPlot library and Qt. Inputs are 2D data points, and outputs are a color-coded plot. ```cpp QCustomPlot *customPlot = new QCustomPlot(); // Setup color map QCPColorMap *colorMap = new QCPColorMap(customPlot->xAxis, customPlot->yAxis); int nx = 200; int ny = 200; colorMap->data()->setSize(nx, ny); colorMap->data()->setRange(QCPRange(-4, 4), QCPRange(-4, 4)); // Fill color map with data double x, y, z; for (int xIndex=0; xIndexdata()->cellToCoord(xIndex, yIndex, &x, &y); double r = 3*qSqrt(x*x+y*y)+1e-2; z = 2*x*(qCos(r+2)/r-qSin(r+2)/r); // dipole radiation pattern colorMap->data()->setCell(xIndex, yIndex, z); } } // Add color scale QCPColorScale *colorScale = new QCPColorScale(customPlot); customPlot->plotLayout()->addElement(0, 1, colorScale); colorScale->setType(QCPAxis::atRight); colorMap->setColorScale(colorScale); colorScale->axis()->setLabel("Magnetic Field Strength"); // Set color gradient (presets: gpGrayscale, gpHot, gpCold, gpNight, // gpCandy, gpGeography, gpIon, gpThermal, gpPolar, gpSpectrum, gpJet, gpHues) colorMap->setGradient(QCPColorGradient::gpPolar); colorMap->rescaleDataRange(); // Synchronize margins QCPMarginGroup *marginGroup = new QCPMarginGroup(customPlot); customPlot->axisRect()->setMarginGroup(QCP::msBottom|QCP::msTop, marginGroup); colorScale->setMarginGroup(QCP::msBottom|QCP::msTop, marginGroup); customPlot->setInteractions(QCP::iRangeDrag|QCP::iRangeZoom); customPlot->rescaleAxes(); customPlot->replot(); ``` -------------------------------- ### Transformation Mode for QCPItemPixmap Source: https://gitlab.com/ecme2/qcustomplot/-/blob/master/changelog.txt Added a parameter to `QCPItemPixmap::setScaled` to specify the transformation mode for scaled pixmaps. This allows control over how the pixmap is resized. Requires `QCPItemPixmap` and `QCustomPlot`. ```cpp // Setting scaled pixmap with transformation mode // QCPItemPixmap *pixmapItem = new QCPItemPixmap(customPlot->axisRect()); // pixmapItem->setPixmap(QPixmap("image.png")); // pixmapItem->setScaled(true, Qt::KeepAspectRatio, Qt::SmoothTransformation); ``` -------------------------------- ### Layer Visibility Control with QCPLayer Source: https://gitlab.com/ecme2/qcustomplot/-/blob/master/changelog.txt Layers in QCustomPlot now have a visibility property controlled by `QCPLayer::setVisible`. This allows selective showing or hiding of layer elements. Requires `QCPLayer` and `QCustomPlot`. ```cpp // Setting layer visibility // QCPLayer *layer = new QCPLayer(customPlot, "myLayer"); // layer->setVisible(false); // Hide the layer ``` -------------------------------- ### Interactive Plotting with QCustomPlot Source: https://context7.com/ecme2/qcustomplot/llms.txt Enables interactive features such as range dragging, zooming, and selection of plottables and axes in QCustomPlot. It also demonstrates synchronizing secondary axes with primary ones and connecting to a click signal for feedback. Requires Qt and QCustomPlot. ```cpp QCustomPlot *customPlot = new QCustomPlot(); // Enable interactions customPlot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables | QCP::iSelectAxes | QCP::iSelectLegend); // Setup full axes box (visible on all sides) customPlot->axisRect()->setupFullAxesBox(); // Synchronize secondary axes with primary axes connect(customPlot->xAxis, SIGNAL(rangeChanged(QCPRange)), customPlot->xAxis2, SLOT(setRange(QCPRange))); connect(customPlot->yAxis, SIGNAL(rangeChanged(QCPRange)), customPlot->yAxis2, SLOT(setRange(QCPRange))); // Add graph data customPlot->addGraph(); QVector x(50), y(50); for (int i=0; i<50; ++i) { x[i] = i; y[i] = qSin(i/5.0); } customPlot->graph(0)->setData(x, y); customPlot->rescaleAxes(); customPlot->replot(); // Connect to click signal for interaction feedback connect(customPlot, SIGNAL(plottableClick(QCPAbstractPlottable*,int,QMouseEvent*)), this, SLOT(graphClicked(QCPAbstractPlottable*,int))); ``` -------------------------------- ### Save and Export QCustomPlot to Image and PDF Source: https://context7.com/ecme2/qcustomplot/llms.txt This snippet demonstrates how to save a QCustomPlot widget to various file formats, including PNG, JPG, BMP, and PDF. It also shows how to copy the plot to the clipboard as a pixmap. Options for resolution, quality, and scaling are available. Requires QCustomPlot and Qt modules. ```cpp QCustomPlot *customPlot = new QCustomPlot(); // After creating your plot... // Save as PNG (high resolution) customPlot->savePng("plot.png", 1920, 1080, 2.0, -1); // 2.0 = scale factor // Save as JPG customPlot->saveJpg("plot.jpg", 1920, 1080, 2.0, 95); // 95 = quality (0-100) // Save as PDF (vector format) customPlot->savePdf("plot.pdf", 400, 300); // width, height in mm // Save as BMP customPlot->saveBmp("plot.bmp", 1920, 1080, 2.0); // Copy to clipboard QPixmap pixmap = customPlot->toPixmap(800, 600, 2.0); QApplication::clipboard()->setPixmap(pixmap); ``` -------------------------------- ### PDF Metadata with QCustomPlot::savePdf Source: https://gitlab.com/ecme2/qcustomplot/-/blob/master/changelog.txt The `QCustomPlot::savePdf` method now accepts optional `pdfCreator` and `pdfTitle` parameters for setting PDF metadata fields. This enhances the ability to generate informative PDF exports. Requires `QCustomPlot`. ```cpp // Saving PDF with metadata // customPlot->savePdf("plot.pdf", 800, 600, "My Plot Title", "My Application", true); // Note: The actual signature may vary, check documentation for exact parameters. ```