QgsColorDialog class

A custom QGIS dialog for selecting a color.

Has many improvements over the standard Qt color picker dialog, including hue wheel supports, color swatches, and a color sampler.

Public static functions

static auto getColor(const QColor& initialColor, QWidget* parent, const QString& title = QString(), bool allowOpacity = false) -> QColor
Returns a color selection from a color dialog.

Constructors, destructors, conversion operators

QgsColorDialog(QWidget* parent = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags, const QColor& color = QColor())
Create a new color picker dialog.

Public functions

auto color() const -> QColor
Returns the current color for the dialog.
void setAllowOpacity(bool allowOpacity)
Sets whether opacity modification (transparency) is permitted for the color dialog.
void setTitle(const QString& title)
Sets the title for the color dialog.

Signals

void currentColorChanged(const QColor& color)
Emitted when the dialog's color changes.

Public slots

void setColor(const QColor& color)
Sets the current color for the dialog.

Function documentation

static QColor QgsColorDialog::getColor(const QColor& initialColor, QWidget* parent, const QString& title = QString(), bool allowOpacity = false)

Returns a color selection from a color dialog.

Parameters
initialColor the initial color of the selection dialog.
parent parent widget
title the title of the dialog.
allowOpacity set to true to allow modification of color opacity value (transparency)
Returns Selected color on accepted() or initialColor on rejected().

QgsColorDialog::QgsColorDialog(QWidget* parent = nullptr, Qt::WindowFlags fl = QgsGuiUtils::ModalDialogFlags, const QColor& color = QColor())

Create a new color picker dialog.

Parameters
parent parent widget
fl window flags
color initial color for dialog

QColor QgsColorDialog::color() const

Returns the current color for the dialog.

Returns dialog color

void QgsColorDialog::setAllowOpacity(bool allowOpacity)

Sets whether opacity modification (transparency) is permitted for the color dialog.

Parameters
allowOpacity set to false to disable opacity modification

Defaults to true.

void QgsColorDialog::setTitle(const QString& title)

Sets the title for the color dialog.

Parameters
title title for dialog box

void QgsColorDialog::currentColorChanged(const QColor& color) signal

Emitted when the dialog's color changes.

Parameters
color current color

void QgsColorDialog::setColor(const QColor& color) public slot

Sets the current color for the dialog.

Parameters
color desired color