Qwt User's Guide: QwtThermo Class Reference

# QwtThermo Class Reference

The Thermometer Widget. More...

`#include <qwt_thermo.h>`

Inheritance diagram for QwtThermo:
[legend]

List of all members.

## Public Types
enum | ScalePos { NoScale, LeftScale, RightScale, TopScale, BottomScale }
## Public Slots
void | setValue (double val)
## Public Member Functions
| QwtThermo (QWidget *parent=NULL)
virtual | ~QwtThermo ()
void | setOrientation (Qt::Orientation o, ScalePos s)
void | setScalePosition (ScalePos s)
ScalePos | scalePosition () const
void | setBorderWidth (int w)
int | borderWidth () const
void | setFillBrush (const QBrush &b)
const QBrush & | fillBrush () const
void | setFillColor (const QColor &c)
const QColor & | fillColor () const
void | setAlarmBrush (const QBrush &b)
const QBrush & | alarmBrush () const
void | setAlarmColor (const QColor &c)
const QColor & | alarmColor () const
void | setAlarmLevel (double v)
double | alarmLevel () const
void | setAlarmEnabled (bool tf)
bool | alarmEnabled () const
void | setPipeWidth (int w)
int | pipeWidth () const
void | setMaxValue (double v)
double | maxValue () const
void | setMinValue (double v)
double | minValue () const
double | value () const
void | setRange (double vmin, double vmax, bool lg=false)
void | setMargin (int m)
virtual QSize | sizeHint () const
virtual QSize | minimumSizeHint () const
void | setScaleDraw (QwtScaleDraw *)
const QwtScaleDraw * | scaleDraw () const
## Protected Member Functions
void | draw (QPainter *p, const QRect &update_rect)
void | drawThermo (QPainter *p)
void | layoutThermo (bool update=true)
virtual void | scaleChange ()
virtual void | fontChange (const QFont &oldFont)
virtual void | paintEvent (QPaintEvent *e)
virtual void | resizeEvent (QResizeEvent *e)
QwtScaleDraw * | scaleDraw ()

## Detailed Description

The Thermometer Widget.

QwtThermo is a widget which displays a value in an interval. It supports:

- a horizontal or vertical layout;
- a range;
- a scale;
- an alarm level.

By default, the scale and range run over the same interval of values. QwtAbstractScale::setScale() changes the interval of the scale and allows easy conversion between physical units.

The example shows how to make the scale indicate in degrees Fahrenheit and to set the value in degrees Kelvin:

    #include <qapplication.h>
    #include <qwt_thermo.h>

    double Kelvin2Fahrenheit(double kelvin)
    {
        // see http://en.wikipedia.org/wiki/Kelvin
        return 1.8*kelvin - 459.67;
    }

    int main(int argc, char **argv)
    {
        const double minKelvin = 0.0;
        const double maxKelvin = 500.0;

        QApplication a(argc, argv);
        QwtThermo t;
        t.setRange(minKelvin, maxKelvin);
        t.setScale(Kelvin2Fahrenheit(minKelvin), Kelvin2Fahrenheit(maxKelvin));
        // set the value in Kelvin but the scale displays in Fahrenheit
        // 273.15 Kelvin = 0 Celsius = 32 Fahrenheit
        t.setValue(273.15);
        a.setMainWidget(&t);
        t.show();
        return a.exec();
    }

## Constructor & Destructor Documentation

QwtThermo::QwtThermo | ( | QWidget * | parent = `NULL` | ) | `[explicit]`

Constructor

Parameters:

  | parent | Parent widget

QwtThermo::~QwtThermo | ( |  | ) | `[virtual]`

Destructor.

## Member Function Documentation

const QBrush & QwtThermo::alarmBrush | ( |  | ) | const

Return the liquid brush above the alarm threshold.

See also:
  setAlarmBrush()

const QColor & QwtThermo::alarmColor | ( |  | ) | const

Return the liquid color above the alarm threshold.

bool QwtThermo::alarmEnabled | ( |  | ) | const

Return if the alarm threshold is enabled or disabled.

double QwtThermo::alarmLevel | ( |  | ) | const

Return the alarm threshold.

See also:
  setAlarmLevel()

int QwtThermo::borderWidth | ( |  | ) | const

Return the border width of the thermometer pipe.

See also:
  setBorderWidth()

void QwtThermo::draw | ( | QPainter * | painter,
|  | const QRect & | rect |
| ) |  |  | `[protected]`

Draw the whole QwtThermo.

Parameters:

  | painter | Painter
  | rect | Update rectangle

void QwtThermo::drawThermo | ( | QPainter * | painter | ) | `[protected]`

Redraw the liquid in thermometer pipe.

Parameters:

  | painter | Painter

const QBrush & QwtThermo::fillBrush | ( |  | ) | const

Return the liquid brush.

See also:
  setFillBrush()

const QColor & QwtThermo::fillColor | ( |  | ) | const

Return the liquid color.

See also:
  setFillColor()

void QwtThermo::fontChange | ( | const QFont & | oldFont | ) | `[protected, virtual]`

Notify a font change.

void QwtThermo::layoutThermo | ( | bool | update_geometry = `true` | ) | `[protected]`

Recalculate the QwtThermo geometry and layout based on the QwtThermo::rect() and the fonts.

Parameters:

  | update_geometry | notify the layout system and call update to redraw the scale

double QwtThermo::maxValue | ( |  | ) | const

Return the maximum value.

QSize QwtThermo::minimumSizeHint | ( |  | ) | const`[virtual]`

Return a minimum size hint.

Warning:
  The return value depends on the font and the scale.

See also:
  sizeHint()

double QwtThermo::minValue | ( |  | ) | const

Return the minimum value.

void QwtThermo::paintEvent | ( | QPaintEvent * | event | ) | `[protected, virtual]`

Qt paint event. event Paint event

int QwtThermo::pipeWidth | ( |  | ) | const

Return the width of the pipe.

See also:
  setPipeWidth()

void QwtThermo::resizeEvent | ( | QResizeEvent * | e | ) | `[protected, virtual]`

Qt resize event handler.

void QwtThermo::scaleChange | ( |  | ) | `[protected, virtual]`

Notify a scale change.

Reimplemented from QwtAbstractScale.

QwtScaleDraw * QwtThermo::scaleDraw | ( |  | ) | `[protected]`

Returns:
  the scale draw of the thermo

See also:
  setScaleDraw()

const QwtScaleDraw * QwtThermo::scaleDraw | ( |  | ) | const

Returns:
  the scale draw of the thermo

See also:
  setScaleDraw()

QwtThermo::ScalePos QwtThermo::scalePosition | ( |  | ) | const

Return the scale position.

See also:
  setScalePosition()

void QwtThermo::setAlarmBrush | ( | const QBrush & | brush | ) |

Specify the liquid brush above the alarm threshold.

Parameters:

  | brush | New brush. The default is solid white.

See also:
  alarmBrush()

void QwtThermo::setAlarmColor | ( | const QColor & | c | ) |

Specify the liquid color above the alarm threshold.

Parameters:

  | c | New color. The default is white.

void QwtThermo::setAlarmEnabled | ( | bool | tf | ) |

Enable or disable the alarm threshold.

Parameters:

  | tf | true (disabled) or false (enabled)

void QwtThermo::setAlarmLevel | ( | double | level | ) |

Specify the alarm threshold.

Parameters:

  | level | Alarm threshold

See also:
  alarmLevel()

void QwtThermo::setBorderWidth | ( | int | width | ) |

Set the border width of the pipe.

Parameters:

  | width | Border width

See also:
  borderWidth()

void QwtThermo::setFillBrush | ( | const QBrush & | brush | ) |

Change the brush of the liquid.

Parameters:

  | brush | New brush. The default brush is solid black.

See also:
  fillBrush()

void QwtThermo::setFillColor | ( | const QColor & | c | ) |

Change the color of the liquid.

Parameters:

  | c | New color. The default color is black.

See also:
  fillColor()

void QwtThermo::setMargin | ( | int | m | ) |

Specify the distance between the pipe's endpoints and the widget's border.

The margin is used to leave some space for the scale labels. If a large font is used, it is advisable to adjust the margins.

Parameters:

  | m | New Margin. The default values are 10 for horizontal orientation and 20 for vertical orientation.

Warning:
  The margin has no effect if the scale is disabled.
  This function is a NOOP because margins are determined automatically.

void QwtThermo::setMaxValue | ( | double | max | ) |

Set the maximum value.

Parameters:

  | max | Maximum value

See also:
  maxValue(), setMinValue()

void QwtThermo::setMinValue | ( | double | min | ) |

Set the minimum value.

Parameters:

  | min | Minimum value

See also:
  minValue(), setMaxValue()

void QwtThermo::setOrientation | ( | Qt::Orientation | o,
|  | ScalePos | s |
| ) |  |  |

Set the thermometer orientation and the scale position.

The scale position NoScale disables the scale.

Parameters:

  | o | orientation. Possible values are Qt::Horizontal and Qt::Vertical. The default value is Qt::Vertical.
  | s | Position of the scale. The default value is NoScale.

A valid combination of scale position and orientation is enforced:

- a horizontal thermometer can have the scale positions TopScale, BottomScale or NoScale;
- a vertical thermometer can have the scale positions LeftScale, RightScale or NoScale;
- an invalid scale position will default to NoScale.

See also:
  setScalePosition()

void QwtThermo::setPipeWidth | ( | int | width | ) |

Change the width of the pipe.

Parameters:

  | width | Width of the pipe

See also:
  pipeWidth()

void QwtThermo::setRange | ( | double | vmin,
|  | double | vmax,
|  | bool | logarithmic = `false` |
| ) |  |  |

Set the range.

Parameters:

  | vmin | value corresponding lower or left end of the thermometer
  | vmax | value corresponding to the upper or right end of the thermometer
  | logarithmic | logarithmic mapping, true or false

void QwtThermo::setScaleDraw | ( | QwtScaleDraw * | scaleDraw | ) |

Set a scale draw.

For changing the labels of the scales, it is necessary to derive from QwtScaleDraw and overload QwtScaleDraw::label().

Parameters:

  | scaleDraw | ScaleDraw object, that has to be created with new and will be deleted in ~QwtThermo or the next call of setScaleDraw().

void QwtThermo::setScalePosition | ( | ScalePos | scalePos | ) |

Change the scale position (and thermometer orientation).

Parameters:

  | scalePos | Position of the scale.

A valid combination of scale position and orientation is enforced:

- if the new scale position is LeftScale or RightScale, the scale orientation will become Qt::Vertical;
- if the new scale position is BottomScale or TopScale, the scale orientation will become Qt::Horizontal;
- if the new scale position is NoScale, the scale orientation will not change.

See also:
  setOrientation(), scalePosition()

void QwtThermo::setValue | ( | double | value | ) | `[slot]`

Set the current value.

Parameters:

  | value | New Value

See also:
  value()

QSize QwtThermo::sizeHint | ( |  | ) | const`[virtual]`

Returns:
  the minimum size hint

See also:
  minimumSizeHint()

double QwtThermo::value | ( |  | ) | const

Return the value.