The QtColorPicker class provides a widget for selecting colors from a popup color grid. More...
#include <qtcolorpicker.h>
Public Slots | |
void | setCurrentColor (const QColor &col) |
Signals | |
void | colorChanged (const QColor &) |
void | colorSet (const QColor &) |
Public Member Functions | |
QColor | color (int index) const |
bool | colorDialogEnabled () const |
QColor | currentColor () const |
void | insertColor (const QColor &color, const QString &text=QString(), int index=-1) |
QtColorPicker (QWidget *parent=nullptr, int columns=-1, bool enableColorDialog=true) | |
void | setColorDialogEnabled (bool enabled) |
void | setStandardColors () |
~QtColorPicker () | |
Static Public Member Functions | |
static QColor | getColor (const QPoint &pos, bool allowCustomColors=true) |
Protected Member Functions | |
void | paintEvent (QPaintEvent *e) |
Properties | |
bool | colorDialog |
Whether the ellipsis "..." (more) button is available. More... | |
The QtColorPicker class provides a widget for selecting colors from a popup color grid.
Users can invoke the color picker by clicking on it, or by navigating to it and pressing Space. They can use the mouse or arrow keys to navigate between colors on the grid, and select a color by clicking or by pressing Enter or Space. The colorChanged() signal is emitted whenever the color picker's color changes.
The widget also supports negative selection: Users can click and hold the mouse button on the QtColorPicker widget, then move the mouse over the color grid and release the mouse button over the color they wish to select.
The color grid shows a customized selection of colors. An optional ellipsis "..." button (signifying "more") can be added at the bottom of the grid; if the user presses this, a QColorDialog pops up and lets them choose any color they like. This button is made available by using setColorDialogEnabled().
When a color is selected, the QtColorPicker widget shows the color and its name. If the name cannot be determined, the translatable name "Custom" is used.
The QtColorPicker object is optionally initialized with the number of columns in the color grid. Colors are then added left to right, top to bottom using insertColor(). If the number of columns is not set, QtColorPicker calculates the number of columns and rows that will make the grid as square as possible.
An alternative to adding colors manually is to initialize the grid with QColorDialog's standard colors using setStandardColors().
QtColorPicker also provides a the static function getColor(), which pops up the grid of standard colors at any given point.
\img colorpicker1.png \img colorpicker2.png
QtColorPicker::QtColorPicker | ( | QWidget * | parent = nullptr , |
int | cols = -1 , |
||
bool | enableColorDialog = true |
||
) |
Constructs a QtColorPicker widget. The popup will display a grid with cols columns, or if cols is -1, the number of columns will be calculated automatically.
If enableColorDialog is true, the popup will also have a "More" button (signified by an ellipsis "...") that presents a QColorDialog when clicked.
After constructing a QtColorPicker, call insertColor() to add individual colors to the popup grid, or call setStandardColors() to add all the standard colors in one go.
The parent argument is passed to QFrame's constructor.
References draftgeoutils.intersections::connect(), and setCurrentColor().
QtColorPicker::~QtColorPicker | ( | ) |
Destructs the QtColorPicker.
QColor QtColorPicker::color | ( | int | index | ) | const |
Returns the color at position index.
References ColorPickerPopup::color().
Referenced by ArchSite.Compass::buildCoordinates(), draftviewproviders.view_dimension.ViewProviderLinearDimension::draw_dim_arrows(), draftviewproviders.view_dimension.ViewProviderAngularDimension::draw_dim_arrows(), draftviewproviders.view_dimension.ViewProviderLinearDimension::draw_dim_overshoot(), draftviewproviders.view_dimension.ViewProviderLinearDimension::draw_ext_overshoot(), draftguitools.gui_trimex.Trimex::finish(), importSVG.svgHandler::format(), DraftGui.DraftToolBar::getcol(), DraftGui.DraftToolBar::getDefaultColor(), PathScripts.PathDressupDogbone.Marker::highlight(), insertColor(), PathScripts.PathDressupDogbone.Marker::lowlight(), ArchPanel.ViewProviderPanelCut::onChanged(), ArchPanel.ViewProviderPanelSheet::onChanged(), draftviewproviders.view_dimension.ViewProviderLinearDimension::onChanged(), draftviewproviders.view_dimension.ViewProviderAngularDimension::onChanged(), FeaturePython.ViewProviderOctahedron::onChanged(), Mod.Test.unittestgui.ProgressBar::paint(), paintEvent(), draftguitools.gui_trackers.editTracker::setColor(), setCurrentColor(), PathScripts.PathDressupTagGui.HoldingTagMarker::setEnabled(), and DraftGui.DraftToolBar::setStyleButton().
|
signal |
This signal is emitted when the QtColorPicker's color is changed. color is the new color.
To obtain the color's name, use text().
Referenced by setCurrentColor().
bool QtColorPicker::colorDialogEnabled | ( | ) | const |
|
signal |
Referenced by setCurrentColor().
QColor QtColorPicker::currentColor | ( | ) | const |
Returns the currently selected color.
|
static |
Pops up a color grid with Qt default colors at point, using global coordinates. If allowCustomColors is true, there will also be a button on the popup that invokes QColorDialog.
For example:
References ColorPickerPopup::exec(), ColorPickerPopup::insertColor(), and ColorPickerPopup::lastSelected().
Referenced by draftguitools.gui_setstyle.Draft_SetStyle_TaskPanel::getPrefColor(), and draftguitools.gui_setstyle.Draft_SetStyle_TaskPanel::setValues().
void QtColorPicker::insertColor | ( | const QColor & | color, |
const QString & | text = QString() , |
||
int | index = -1 |
||
) |
Adds the color color with the name text to the color grid, at position index. If index is -1, the color is assigned automatically assigned a position, starting from left to right, top to bottom.
References color(), and ColorPickerPopup::insertColor().
Referenced by setCurrentColor(), and setStandardColors().
|
protected |
References color().
void QtColorPicker::setColorDialogEnabled | ( | bool | enabled | ) |
|
slot |
Makes color current. If color is not already in the color grid, it is inserted with the text "Custom".
This function emits the colorChanged() signal if the new color is valid, and different from the old one.
References color(), colorChanged(), colorSet(), ColorPickerPopup::find(), insertColor(), ColorPickerPopup::setLastSel(), ColorPickerItem::setSelected(), and ColorPickerItem::text().
Referenced by SpreadsheetGui::Workbench::activated(), SpreadsheetGui::PropertiesDialog::PropertiesDialog(), and QtColorPicker().
void QtColorPicker::setStandardColors | ( | ) |
Adds the 17 predefined colors from the Qt namespace.
(The names given to the colors, "Black", "White", "Red", etc., are all translatable.)
References insertColor().
Referenced by SpreadsheetGui::Workbench::activated(), and SpreadsheetGui::PropertiesDialog::PropertiesDialog().
|
readwrite |
Whether the ellipsis "..." (more) button is available.
If this property is set to true, the color grid popup will include a "More" button (signified by an ellipsis, "...") which pops up a QColorDialog when clicked. The user will then be able to select any custom color they like.