Class: QgsColorRampButton

A cross platform button subclass for selecting color ramps.

Will open color ramp dialogs when clicked.

Offers live updates to button from color ramp dialog. An attached drop-down menu allows for access to saved color ramps, as well as option to invert the current color ramp and create new ramps.

Class Hierarchy

Inheritance diagram of qgis.gui.QgsColorRampButton

Base classes

QToolButton

QAbstractButton

QWidget

QObject

QPaintDevice

class qgis.gui.QgsColorRampButton[source]

Bases: QToolButton

__init__(parent: QWidget | None = None, dialogTitle: str | None = '')

Construct a new color ramp button. Use parent to attach a parent QWidget to the dialog. Use dialogTitle string to define the title to show in the color ramp dialog

Parameters:
  • parent (Optional[QWidget] = None)

  • dialogTitle (Optional[str] = '')

acceptLiveUpdates(self) bool[source]

Returns whether the button accepts live updates from QgsColorRampDialog.

Return type:

bool

Returns:

True if the button will be accepted immediately when the dialog’s color ramp changes

colorRamp(self) QgsColorRamp | None[source]

Returns a copy of the current color ramp.

See also

setColorRamp()

Return type:

Optional[QgsColorRamp]

signal colorRampChanged[source]

pyqtSignal(*types, name: str = …, revision: int = …, arguments: Sequence = …) -> PYQT_SIGNAL

types is normally a sequence of individual types. Each type is either a type object or a string that is the name of a C++ type. Alternatively each type could itself be a sequence of types each describing a different overloaded signal. name is the optional C++ name of the signal. If it is not specified then the name of the class attribute that is bound to the signal is used. revision is the optional revision of the signal that is exported to QML. If it is not specified then 0 is used. arguments is the optional sequence of the names of the signal’s arguments.

colorRampDialogTitle(self) str[source]

Returns the title for the color ramp dialog window.

Return type:

str

Returns:

title for the color ramp dialog

colorRampName(self) str[source]

Returns the name of the current color ramp when it’s available in the style manager

Return type:

str

context(self) str[source]

Returns the context string for the color ramp button. The context string is passed to all color ramp preview icons shown in the button’s drop-down menu, to (eventually) allow them to customize their display colors based on the context.

Return type:

str

Returns:

context context string for the color dialog button’s color ramp preview icons

See also

setContext()

defaultColorRamp(self) QgsColorRamp | None[source]

Returns a copy of the default color ramp for the button, which is shown in the button’s drop-down menu for the “default color ramp” option.

Return type:

Optional[QgsColorRamp]

Returns:

default color ramp for the button. Returns None if the default color ramp option is disabled. Caller takes ownership of the returned object.

isNull(self) bool[source]

Returns True if the current color ramp is null.

See also

setShowNull()

See also

showNull()

Return type:

bool

isRandomColorRamp(self) bool[source]

Returns True if the current color ramp is random.

See also

setShowNull()

See also

showNull()

Return type:

bool

virtual mousePressEvent(self, e: QMouseEvent | None)[source]

Reimplemented to detect right mouse button clicks on the color ramp button

Parameters:

e (Optional[QMouseEvent])

setAcceptLiveUpdates(self, accept: bool)[source]

Sets whether the button accepts live updates from QgsColorRampDialog. Live updates may cause changes that are not undoable on QColorRampDialog cancel.

Parameters:

accept (bool) – set to True to enable live updates

setButtonBackground(self, colorramp: QgsColorRamp | None = None)[source]

Sets the background pixmap for the button based upon current color ramp.

Parameters:

colorramp (Optional[QgsColorRamp] = None) – Color ramp for button background. If no color ramp is specified, the button’s current color ramp will be used

setColorRamp(self, colorramp: QgsColorRamp | None)[source]

Sets the current color ramp for the button. Will emit a colorRampChanged() signal if the color ramp is different to the previous color ramp.

Parameters:

colorramp (Optional[QgsColorRamp]) – New color ramp for the button. The ramp will be cloned and ownership is not transferred.

See also

colorRamp()

setColorRampDialogTitle(self, title: str | None)[source]

Set the title for the color ramp dialog window.

Parameters:

title (Optional[str]) – Title for the color ramp dialog

setColorRampFromName(self, name: str | None = '')[source]

Sets the current color ramp for the button using a saved color ramp name. Will emit a colorRampChanged() signal if the color ramp is different to the previous color ramp.

Parameters:

name (Optional[str] = '') – Name of saved color ramp

See also

setColorRamp()

See also

colorRamp()

setColorRampName(self, name: str | None)[source]

Sets the name of the current color ramp when it’s available in the style manager

Parameters:

name (Optional[str]) – Name of the saved color ramp

See also

colorRampName()

setContext(self, context: str | None)[source]

Sets the context string for the color ramp button. The context string is passed to all color ramp preview icons shown in the button’s drop-down menu, to (eventually) allow them to customize their display colors based on the context.

Parameters:

context (Optional[str]) – context string for the color dialog button’s color ramp preview icons

See also

context()

setDefaultColorRamp(self, colorramp: QgsColorRamp | None)[source]

Sets the default color ramp for the button, which is shown in the button’s drop-down menu for the “default color ramp” option.

Parameters:

colorramp (Optional[QgsColorRamp]) – default color ramp for the button. Set to None to disable the default color ramp option. The ramp will be cloned and ownership is not transferred.

setRandomColorRamp(self)[source]

Sets the current color ramp for the button to random colors. Will emit a colorRampChanged() signal if the color ramp is different to the previous color ramp.

See also

setColorRamp()

See also

colorRamp()

setShowGradientOnly(self, gradientonly: bool)[source]

Sets whether the color ramp button only shows gradient type ramps

Parameters:

gradientonly (bool) – set to True to show only gradient type ramps

setShowMenu(self, showMenu: bool)[source]

Sets whether the drop-down menu should be shown for the button. The default behavior is to show the menu.

Parameters:

showMenu (bool) – set to False to hide the drop-down menu

See also

showMenu()

setShowNull(self, showNull: bool)[source]

Sets whether a set to null (clear) option is shown in the button’s drop-down menu.

Parameters:

showNull (bool) – set to True to show a null option

See also

showNull()

See also

isNull()

setShowRandomColorRamp(self, showRandom: bool)[source]

Sets whether a random colors option is shown in the button’s drop-down menu.

Parameters:

showRandom (bool) – set to True to show a random colors option

setToDefaultColorRamp(self)[source]

Sets color ramp to the button’s default color ramp, if set.

See also

setToNull()

setToNull(self)[source]

Sets color ramp to null.

showGradientOnly(self) bool[source]

Returns True if the color ramp button only shows gradient type ramps

Return type:

bool

showMenu(self) bool[source]

Returns whether the drop-down menu is shown for the button.

Return type:

bool

Returns:

True if drop-down menu is shown

See also

setShowMenu()

showNull(self) bool[source]

Returns whether the set to null (clear) option is shown in the button’s drop-down menu.

See also

setShowNull()

See also

isNull()

Return type:

bool

showRandomColorRamp(self) bool[source]

Returns whether random colors option is shown in the button’s drop-down menu.

Return type:

bool