QWT API (English) 7.3.0
Qt Widget Library for Technical Applications - English API Documentation
Loading...
Searching...
No Matches
Functions
qwt_utils.h File Reference

Qwt plot utility classes collection and compatibility functions. More...

#include "qwt_global.h"
#include <qsize.h>
#include "qwt_plot_factory.h"
#include "qwt_plot_item_info.h"
#include "qwt_plot_data_access.h"
#include "qwt_plot_transform.h"
#include "qwt_plot_styling.h"
#include "qwt_pyplot.h"

Go to the source code of this file.

Functions

QSize QWT_EXPORT qwtExpandedToGlobalStrut (const QSize &size)
 Expand a size to the global strut (Qt5/Qt6 compatibility function)
 

Detailed Description

Qwt plot utility classes collection and compatibility functions.

This file provides two main features:

  1. Forward includes for plot utility classes: Including this file gives access to all Qwt plot utility classes at once. These utility classes replace the deprecated Qwt::plotItemColor() function with more powerful and type-safe functionality.
  2. Qt version compatibility function: qwtExpandedToGlobalStrut() handles the globalStrut API difference between Qt 5 and Qt 6, primarily used internally by Qwt widget classes.

Plot Utility Classes

Since Qwt 7.x, the following 5 dedicated utility classes are recommended for working with plot items:

All classes are in the Qwt namespace and provide type-safe, rtti-dispatched APIs that are safer and more efficient than the old dynamic_cast approach.

Example

#include <qwt_utils.h>
// Create a plot
QwtPlot* plot = new QwtPlot();
// Create a curve using factory method
QVector<QPointF> points = {{0,0}, {1,1}, {2,4}};
QwtPlotCurve* curve = QwtPlotFactory::createCurve(plot, "Temperature", points);
// Query type
// Handle series item
}
// Read data
// Set style
QwtPlotStyling::setColor(curve, Qt::blue);
QwtPlotStyling::setPenWidth(curve, 2.0);
// Coordinate transformation
QPointF plotPos = QwtPlotTransform::toPlotCoordinates(plot, screenPos);
Definition qwt_clipper.h:41
A plot item, that represents a series of points.
Definition qwt_plot_curve.h:75
static QVector< QPointF > xySamples(const QwtPlotItem *item)
Extract XY samples from a plot item.
Definition qwt_plot_data_access.cpp:48
static QwtPlotCurve * createCurve(QwtPlot *plot, const QString &title, const QVector< QPointF > &data, QwtAxisId xAxis=QwtAxis::XBottom, QwtAxisId yAxis=QwtAxis::YLeft)
Create a curve from QPointF data and attach it to a plot.
Definition qwt_plot_factory.cpp:46
static bool isSeriesItem(const QwtPlotItem *item)
Check whether the item is a QwtPlotSeriesItem subclass.
Definition qwt_plot_item_info.cpp:31
static bool setColor(QwtPlotItem *item, const QColor &color)
Set the color of a plot item.
Definition qwt_plot_styling.cpp:93
A 2-D plotting widget.
Definition qwt_plot.h:99
Qwt plot utility classes collection and compatibility functions.

Guide

If you were using Qwt::plotItemColor(), you should now use QwtPlotStyling::color():

// Old way (deprecated)
QColor color = Qwt::plotItemColor(item);
// New way (recommended)
QColor color = QwtPlotStyling::color(item);
static QColor color(const QwtPlotItem *item, const QColor &defaultColor=QColor())
Get the representative color of a plot item.
Definition qwt_plot_styling.cpp:38

The new approach supports more plot item types and uses rtti dispatch instead of dynamic_cast for better performance.

Note
The qwtExpandedToGlobalStrut() function is retained for internal Qwt use only. Application code should not call this function directly.

Function Documentation

◆ qwtExpandedToGlobalStrut()

QSize QWT_EXPORT qwtExpandedToGlobalStrut ( const QSize &  size)

Expand a size to the global strut (Qt5/Qt6 compatibility function)

In Qt 5.0-5.14, QApplication::globalStrut() returns the application-defined minimum widget size. This function expands the given size to at least that minimum size.

In Qt 5.15+ and Qt 6, globalStrut() has been removed and this function returns the original size unchanged.

Parameters
sizeOriginal size
Returns
Size expanded to the global strut, or the original size on Qt 5.15+/Qt 6