QgsScaleWidget class

A combobox which lets the user select map scale from predefined list and highlights nearest to current scale value.

Public static functions

static auto toDouble(const QString& scaleString, bool* ok = nullptr) -> double
Helper function to convert a scale string to double.
static auto toString(double scale) -> QString
Helper function to convert a scale double to scale string.

Constructors, destructors, conversion operators

QgsScaleWidget(QWidget* parent = nullptr) explicit
QgsScaleWidget creates a combobox which lets the user select map scale from predefined list and highlights nearest to current scale value.

Public functions

auto minScale() const -> double
Returns the minimum scale, or 0 if no minimum scale set.
auto scale() const -> double
Returns the selected scale as a double.
auto scaleString() const -> QString
Returns the selected scale as a string, e.g.
void setMapCanvas(QgsMapCanvas* canvas)
Set the map canvas associated to the current button.
auto setScaleString(const QString& string) -> bool
Set the selected scale from a string, e.g.
void setShowCurrentScaleButton(bool showCurrentScaleButton)
Sets whether to show a button to set the scale to the current scale of the map canvas next to the combobox.
auto showCurrentScaleButton() -> bool
Returns whether a button to set the scale from map canvas is shown or not.

Signals

void scaleChanged(double scale)
Emitted when user has finished editing/selecting a new scale.

Public slots

void setMinScale(double scale)
Set the minimum allowed scale.
void setScale(double scale)
Set the selected scale from a double.
void setScaleFromCanvas()
Assigns the current scale from the map canvas, if set.
void updateScales(const QStringList& scales = QStringList())
Sets the list of predefined scales to show in the combobox.

Function documentation

static double QgsScaleWidget::toDouble(const QString& scaleString, bool* ok = nullptr)

Helper function to convert a scale string to double.

The returned value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map. If specified, ok will be set to true if the string was successfully interpreted as a scale.

static QString QgsScaleWidget::toString(double scale)

Helper function to convert a scale double to scale string.

The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.

The returned string will be rounded (e.g. 1:1000, not 1:1000.345).

double QgsScaleWidget::minScale() const

Returns the minimum scale, or 0 if no minimum scale set.

The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map. Any scale lower than the minimum scale will automatically be converted to the minimum scale. Except for 0 which is always allowed.

double QgsScaleWidget::scale() const

Returns the selected scale as a double.

The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.

QString QgsScaleWidget::scaleString() const

Returns the selected scale as a string, e.g.

"1:150".

bool QgsScaleWidget::setScaleString(const QString& string)

Set the selected scale from a string, e.g.

"1:150".

void QgsScaleWidget::setShowCurrentScaleButton(bool showCurrentScaleButton)

Sets whether to show a button to set the scale to the current scale of the map canvas next to the combobox.

bool QgsScaleWidget::showCurrentScaleButton()

Returns whether a button to set the scale from map canvas is shown or not.

void QgsScaleWidget::scaleChanged(double scale) signal

Emitted when user has finished editing/selecting a new scale.

The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.

void QgsScaleWidget::setMinScale(double scale) public slot

Set the minimum allowed scale.

Set to 0 to disable the minimum scale. The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map. Any scale lower than the minimum scale will automatically be converted to the minimum scale. Except for 0 which is always allowed.

void QgsScaleWidget::setScale(double scale) public slot

Set the selected scale from a double.

The scale value indicates the scale denominator, e.g. 1000.0 for a 1:1000 map.

void QgsScaleWidget::setScaleFromCanvas() public slot

Assigns the current scale from the map canvas, if set.

void QgsScaleWidget::updateScales(const QStringList& scales = QStringList()) public slot

Sets the list of predefined scales to show in the combobox.

List elements are expected to be valid scale strings, such as "1:1000000".