QGIS API Documentation 3.28.0-Firenze (ed3ad0430f)
|
A cross platform button subclass for selecting colors. More...
#include <qgscolorbutton.h>
Public Types | |
enum | Behavior { ShowDialog = 0 , SignalOnly } |
Specifies the behavior when the button is clicked. More... | |
Public Slots | |
void | activatePicker () |
Activates the color picker tool, which allows for sampling a color from anywhere on the screen. More... | |
void | copyColor () |
Copies the current color to the clipboard. More... | |
void | pasteColor () |
Pastes a color from the clipboard to the color button. More... | |
void | setButtonBackground (const QColor &color=QColor()) |
Sets the background pixmap for the button based upon color and transparency. More... | |
void | setColor (const QColor &color) |
Sets the current color for the button. More... | |
void | setToDefaultColor () |
Sets color to the button's default color, if set. More... | |
void | setToNoColor () |
Sets color to a totally transparent color. More... | |
void | setToNull () |
Sets color to null. More... | |
void | unlink () |
Unlinks the button from a project color. More... | |
Signals | |
void | cleared () |
Emitted when the color is cleared (set to null). More... | |
void | colorChanged (const QColor &color) |
Emitted whenever a new color is set for the button. More... | |
void | colorClicked (const QColor &color) |
Emitted when the button is clicked, if the button's behavior is set to SignalOnly. More... | |
void | unlinked () |
Emitted when the color is unlinked, e.g. More... | |
Public Member Functions | |
QgsColorButton (QWidget *parent=nullptr, const QString &cdt=QString(), QgsColorSchemeRegistry *registry=nullptr) | |
Construct a new color ramp button. More... | |
bool | allowOpacity () const |
Returns whether opacity modification (transparency) is permitted for the color. More... | |
Behavior | behavior () const |
Returns the behavior for when the button is clicked. More... | |
QColor | color () const |
Returns the currently selected color. More... | |
QString | colorDialogTitle () const |
Returns the title for the color chooser dialog window. More... | |
QgsColorSchemeRegistry * | colorSchemeRegistry () |
Returns the color scheme registry for the button, which controls the color swatch grids that are shown in the button's drop-down menu. More... | |
QString | context () const |
Returns the context string for the color button. More... | |
QColor | defaultColor () const |
Returns the default color for the button, which is shown in the button's drop-down menu for the "default color" option. More... | |
bool | isNull () const |
Returns true if the current color is null. More... | |
QString | linkedProjectColorName () const |
Returns the linked project color name, if set. More... | |
void | linkToProjectColor (const QString &name) |
Sets the button to link to an existing project color, by color name. More... | |
QSize | minimumSizeHint () const override |
QString | noColorString () const |
Returns the string used for the "no color" option in the button's drop-down menu. More... | |
void | setAllowOpacity (bool allowOpacity) |
Sets whether opacity modification (transparency) is permitted for the color. More... | |
void | setBehavior (Behavior behavior) |
Sets the behavior for when the button is clicked. More... | |
void | setColorDialogTitle (const QString &title) |
Set the title for the color chooser dialog window. More... | |
void | setColorSchemeRegistry (QgsColorSchemeRegistry *registry) |
Sets the color scheme registry for the button, which controls the color swatch grids that are shown in the button's drop-down menu. More... | |
void | setContext (const QString &context) |
Sets the context string for the color button. More... | |
void | setDefaultColor (const QColor &color) |
Sets the default color for the button, which is shown in the button's drop-down menu for the "default color" option. More... | |
void | setNoColorString (const QString &noColorString) |
Sets the string to use for the "no color" option in the button's drop-down menu. More... | |
void | setShowMenu (bool showMenu) |
Sets whether the drop-down menu should be shown for the button. More... | |
void | setShowNoColor (const bool showNoColorOption) |
Sets whether the "no color" option should be shown in the button's drop-down menu. More... | |
void | setShowNull (bool showNull, const QString &nullString=QString()) |
Sets whether a set to null (clear) option is shown in the button's drop-down menu. More... | |
bool | showMenu () const |
Returns whether the drop-down menu is shown for the button. More... | |
bool | showNoColor () const |
Returns whether the "no color" option is shown in the button's drop-down menu. More... | |
bool | showNull () const |
Returns whether the set to null (clear) option is shown in the button's drop-down menu. More... | |
QSize | sizeHint () const override |
Static Public Member Functions | |
static QPixmap | createMenuIcon (const QColor &color, bool showChecks=true) |
Creates an icon for displaying a color in a drop-down menu. More... | |
Protected Member Functions | |
void | changeEvent (QEvent *e) override |
void | dragEnterEvent (QDragEnterEvent *e) override |
Reimplemented to accept dragged colors. More... | |
void | dragLeaveEvent (QDragLeaveEvent *e) override |
Reimplemented to reset button appearance after drag leave. More... | |
void | dropEvent (QDropEvent *e) override |
Reimplemented to accept dropped colors. More... | |
bool | event (QEvent *e) override |
void | keyPressEvent (QKeyEvent *e) override |
Reimplemented to allow canceling color pick via keypress, and sample via space bar press. More... | |
void | mouseMoveEvent (QMouseEvent *e) override |
Reimplemented to allow dragging colors from button. More... | |
void | mousePressEvent (QMouseEvent *e) override |
Reimplemented to detect right mouse button clicks on the color button and allow dragging colors. More... | |
void | mouseReleaseEvent (QMouseEvent *e) override |
Reimplemented to allow color picking. More... | |
void | resizeEvent (QResizeEvent *event) override |
void | showEvent (QShowEvent *e) override |
void | wheelEvent (QWheelEvent *event) override |
Static Protected Member Functions | |
static const QPixmap & | transparentBackground () |
Returns a checkboard pattern pixmap for use as a background to transparent colors. More... | |
Properties | |
bool | allowOpacity |
Behavior | behavior |
QColor | color |
QString | colorDialogTitle |
QString | context |
QColor | defaultColor |
QString | noColorString |
bool | showMenu |
bool | showNoColor |
A cross platform button subclass for selecting colors.
Will open a color chooser dialog when clicked. Offers live updates to button from color chooser dialog. An attached drop-down menu allows for copying and pasting colors, picking colors from the screen, and selecting colors from color swatch grids.
Definition at line 35 of file qgscolorbutton.h.
Specifies the behavior when the button is clicked.
Enumerator | |
---|---|
ShowDialog | Show a color picker dialog when clicked. |
SignalOnly | Emit colorClicked signal only, no dialog. |
Definition at line 64 of file qgscolorbutton.h.
QgsColorButton::QgsColorButton | ( | QWidget * | parent = nullptr , |
const QString & | cdt = QString() , |
||
QgsColorSchemeRegistry * | registry = nullptr |
||
) |
Construct a new color ramp button.
Use parent to attach a parent QWidget to the dialog. Use cdt string to define the title to show in the color ramp dialog Use a color scheme registry for color swatch grids to show in the drop-down menu. If not specified, the button will use the global color scheme registry instead
Definition at line 43 of file qgscolorbutton.cpp.
|
slot |
Activates the color picker tool, which allows for sampling a color from anywhere on the screen.
Definition at line 785 of file qgscolorbutton.cpp.
|
inline |
Returns whether opacity modification (transparency) is permitted for the color.
true
if opacity modification is allowed Definition at line 106 of file qgscolorbutton.h.
|
inline |
Returns the behavior for when the button is clicked.
Definition at line 150 of file qgscolorbutton.h.
|
overrideprotected |
Definition at line 623 of file qgscolorbutton.cpp.
|
signal |
QColor QgsColorButton::color | ( | ) | const |
Returns the currently selected color.
Definition at line 797 of file qgscolorbutton.cpp.
|
signal |
Emitted whenever a new color is set for the button.
The color is always valid. In case the new color is the same no signal is emitted, to avoid infinite loops.
color | New color |
|
signal |
Emitted when the button is clicked, if the button's behavior is set to SignalOnly.
color | button color |
QString QgsColorButton::colorDialogTitle | ( | ) | const |
Returns the title for the color chooser dialog window.
Definition at line 815 of file qgscolorbutton.cpp.
|
inline |
Returns the color scheme registry for the button, which controls the color swatch grids that are shown in the button's drop-down menu.
Definition at line 272 of file qgscolorbutton.h.
|
inline |
Returns the context string for the color button.
The context string is passed to all color swatch grids shown in the button's drop-down menu, to allow them to customize their display colors based on the context.
Definition at line 254 of file qgscolorbutton.h.
|
slot |
Copies the current color to the clipboard.
Definition at line 765 of file qgscolorbutton.cpp.
|
static |
Creates an icon for displaying a color in a drop-down menu.
If showChecks set to true
, then a checkboard pattern will be shown behind semi-transparent colors.
Definition at line 459 of file qgscolorbutton.cpp.
|
inline |
Returns the default color for the button, which is shown in the button's drop-down menu for the "default color" option.
Definition at line 168 of file qgscolorbutton.h.
|
overrideprotected |
Reimplemented to accept dragged colors.
Definition at line 381 of file qgscolorbutton.cpp.
|
overrideprotected |
Reimplemented to reset button appearance after drag leave.
Definition at line 399 of file qgscolorbutton.cpp.
|
overrideprotected |
Reimplemented to accept dropped colors.
Definition at line 406 of file qgscolorbutton.cpp.
|
overrideprotected |
Definition at line 169 of file qgscolorbutton.cpp.
bool QgsColorButton::isNull | ( | ) | const |
Returns true
if the current color is null.
Definition at line 851 of file qgscolorbutton.cpp.
|
overrideprotected |
Reimplemented to allow canceling color pick via keypress, and sample via space bar press.
Definition at line 368 of file qgscolorbutton.cpp.
|
inline |
Returns the linked project color name, if set.
Definition at line 296 of file qgscolorbutton.h.
void QgsColorButton::linkToProjectColor | ( | const QString & | name | ) |
Sets the button to link to an existing project color, by color name.
This changes the behavior of the button to a "linked" mode. Specifically, the button will show the linked color and respond to changes in the project color scheme by refreshing the displayed color automatically. Additionally, the button's menu will show items specific to linked color mode, including an option to "unlink" from the project color.
Definition at line 856 of file qgscolorbutton.cpp.
|
override |
Definition at line 76 of file qgscolorbutton.cpp.
|
overrideprotected |
Reimplemented to allow dragging colors from button.
Definition at line 277 of file qgscolorbutton.cpp.
|
overrideprotected |
Reimplemented to detect right mouse button clicks on the color button and allow dragging colors.
Definition at line 231 of file qgscolorbutton.cpp.
|
overrideprotected |
Reimplemented to allow color picking.
Definition at line 313 of file qgscolorbutton.cpp.
|
inline |
Returns the string used for the "no color" option in the button's drop-down menu.
Definition at line 236 of file qgscolorbutton.h.
|
slot |
Pastes a color from the clipboard to the color button.
If clipboard does not contain a valid color or string representation of a color, then no change is applied.
Definition at line 774 of file qgscolorbutton.cpp.
|
overrideprotected |
Definition at line 650 of file qgscolorbutton.cpp.
void QgsColorButton::setAllowOpacity | ( | bool | allowOpacity | ) |
Sets whether opacity modification (transparency) is permitted for the color.
Defaults to false
.
allowOpacity | set to true to allow opacity modification |
Definition at line 805 of file qgscolorbutton.cpp.
void QgsColorButton::setBehavior | ( | const QgsColorButton::Behavior | behavior | ) |
Sets the behavior for when the button is clicked.
The default behavior is to show a color picker dialog.
behavior | behavior when button is clicked |
Definition at line 830 of file qgscolorbutton.cpp.
|
slot |
Sets the background pixmap for the button based upon color and transparency.
Call directly to update background after adding/removing QColorDialog::ShowAlphaChannel option but the color has not changed, i.e. setColor() wouldn't update button and you want the button to retain the set color's alpha component regardless
color | Color for button background. If no color is specified, the button's current color will be used |
Definition at line 682 of file qgscolorbutton.cpp.
|
slot |
Sets the current color for the button.
Will emit a colorChanged signal if the color is different to the previous color.
color | new color for the button |
Definition at line 658 of file qgscolorbutton.cpp.
void QgsColorButton::setColorDialogTitle | ( | const QString & | title | ) |
Set the title for the color chooser dialog window.
title | Title for the color chooser dialog |
Definition at line 810 of file qgscolorbutton.cpp.
|
inline |
Sets the color scheme registry for the button, which controls the color swatch grids that are shown in the button's drop-down menu.
registry | color scheme registry for the button. Set to 0 to hide all color swatch grids from the button's drop-down menu. |
Definition at line 263 of file qgscolorbutton.h.
|
inline |
Sets the context string for the color button.
The context string is passed to all color swatch grids shown in the button's drop-down menu, to allow them to customize their display colors based on the context.
context | context string for the color button's color swatch grids |
Definition at line 245 of file qgscolorbutton.h.
void QgsColorButton::setDefaultColor | ( | const QColor & | color | ) |
Sets the default color for the button, which is shown in the button's drop-down menu for the "default color" option.
color | default color for the button. Set to an invalid QColor to disable the default color option. |
Definition at line 835 of file qgscolorbutton.cpp.
|
inline |
Sets the string to use for the "no color" option in the button's drop-down menu.
noColorString | string to use for the "no color" menu option |
Definition at line 200 of file qgscolorbutton.h.
void QgsColorButton::setShowMenu | ( | bool | showMenu | ) |
Sets whether the drop-down menu should be shown for the button.
The default behavior is to show the menu.
showMenu | set to false to hide the drop-down menu |
Definition at line 820 of file qgscolorbutton.cpp.
|
inline |
Sets whether the "no color" option should be shown in the button's drop-down menu.
If selected, the "no color" option sets the color button's color to a totally transparent color.
showNoColorOption | set to true to show the no color option. This is disabled by default. |
Definition at line 179 of file qgscolorbutton.h.
void QgsColorButton::setShowNull | ( | bool | showNull, |
const QString & | nullString = QString() |
||
) |
Sets whether a set to null (clear) option is shown in the button's drop-down menu.
showNull | set to true to show a null option |
nullString | translated string to use for the null option. If not set, a default "Clear Color" string will be used. |
Definition at line 840 of file qgscolorbutton.cpp.
|
slot |
Sets color to the button's default color, if set.
Definition at line 147 of file qgscolorbutton.cpp.
|
slot |
Sets color to a totally transparent color.
Definition at line 224 of file qgscolorbutton.cpp.
|
slot |
|
overrideprotected |
Definition at line 644 of file qgscolorbutton.cpp.
|
inline |
Returns whether the drop-down menu is shown for the button.
true
if drop-down menu is shown Definition at line 135 of file qgscolorbutton.h.
|
inline |
Returns whether the "no color" option is shown in the button's drop-down menu.
If selected, the "no color" option sets the color button's color to a totally transparent color.
true
if the no color option is shown. Definition at line 190 of file qgscolorbutton.h.
bool QgsColorButton::showNull | ( | ) | const |
Returns whether the set to null (clear) option is shown in the button's drop-down menu.
Definition at line 846 of file qgscolorbutton.cpp.
|
override |
Definition at line 81 of file qgscolorbutton.cpp.
|
staticprotected |
Returns a checkboard pattern pixmap for use as a background to transparent colors.
Definition at line 86 of file qgscolorbutton.cpp.
|
slot |
Unlinks the button from a project color.
Definition at line 163 of file qgscolorbutton.cpp.
|
signal |
Emitted when the color is unlinked, e.g.
when it was previously set to link to a project color and is now no longer linked.
|
overrideprotected |
Definition at line 423 of file qgscolorbutton.cpp.
|
readwrite |
Definition at line 35 of file qgscolorbutton.h.
|
readwrite |
Definition at line 35 of file qgscolorbutton.h.
|
readwrite |
Definition at line 35 of file qgscolorbutton.h.
|
readwrite |
Definition at line 35 of file qgscolorbutton.h.
|
readwrite |
Definition at line 35 of file qgscolorbutton.h.
|
readwrite |
Definition at line 35 of file qgscolorbutton.h.
|
readwrite |
Definition at line 35 of file qgscolorbutton.h.
|
readwrite |
Definition at line 35 of file qgscolorbutton.h.
|
readwrite |
Definition at line 35 of file qgscolorbutton.h.