QGIS API Documentation  2.5.0-Master
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Public Slots | Signals | Public Member Functions | Protected Member Functions | Static Protected Member Functions | List of all members
QgsColorButton Class Reference

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. More...

#include <qgscolorbutton.h>

Inheritance diagram for QgsColorButton:
Inheritance graph
[legend]

Public Slots

void setButtonBackground (QColor color=QColor())
 Sets the background pixmap for the button based upon color and transparency. More...
 

Signals

void colorChanged (const QColor &color)
 Is emitted, whenever a new color is accepted. More...
 

Public Member Functions

 QgsColorButton (QWidget *parent=0, QString cdt="", QColorDialog::ColorDialogOptions cdo=0)
 Construct a new color button. More...
 
 ~QgsColorButton ()
 
void setColor (const QColor &color)
 Specify the current color. More...
 
QColor color () const
 Return the currently selected color. More...
 
void setColorDialogOptions (QColorDialog::ColorDialogOptions cdo)
 Specify the options for the color chooser dialog (e.g. More...
 
QColorDialog::ColorDialogOptions colorDialogOptions ()
 Returns the options for the color chooser dialog. More...
 
void setColorDialogTitle (QString cdt)
 Set the title, which the color chooser dialog will show. More...
 
QString colorDialogTitle ()
 Returns the title, which the color chooser dialog shows. More...
 
bool acceptLiveUpdates ()
 Whether the button accepts live updates from QColorDialog. More...
 
void setAcceptLiveUpdates (bool accept)
 Sets whether the button accepts live updates from QColorDialog. More...
 

Protected Member Functions

void changeEvent (QEvent *e)
 
void showEvent (QShowEvent *e)
 
void mousePressEvent (QMouseEvent *e)
 Reimplemented to detect right mouse button clicks on the color button and allow dragging colors. More...
 
void mouseMoveEvent (QMouseEvent *e)
 Reimplemented to allow dragging colors from button. More...
 
void mouseReleaseEvent (QMouseEvent *e)
 Reimplemented to allow color picking. More...
 
void keyPressEvent (QKeyEvent *e)
 Reimplemented to allow cancelling color pick via keypress, and sample via space bar press. More...
 
void dragEnterEvent (QDragEnterEvent *e)
 Reimplemented to accept dragged colors. More...
 
void dropEvent (QDropEvent *e)
 Reimplemented to accept dropped colors. More...
 

Static Protected Member Functions

static const QPixmap & transpBkgrd ()
 

Detailed Description

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.

A cross platform button subclass for selecting colors.

A subclass of QPushButton is needed to draw the button content because some platforms such as Mac OS X and Windows XP enforce a consistent GUI look by always using the button color of the current style and not allowing button backgrounds to be changed on a button by button basis. Therefore, a wholely stylesheet-based button is used for the no-text variant.

This class is a simplified version of QtColorButton, an internal class used by Qt Designer to do the same thing.

Will open a color chooser dialog when clicked. Offers live updates to button from color chooser dialog

Note
inherited base class moved from QToolButton to QPushButton in QGIS 1.9

Constructor & Destructor Documentation

QgsColorButton::QgsColorButton ( QWidget *  parent = 0,
QString  cdt = "",
QColorDialog::ColorDialogOptions  cdo = 0 
)

Construct a new color button.

Parameters
parentThe parent QWidget for the dialog
cdtThe title to show in the color chooser dialog
cdoOptions for the color chooser dialog
Note
changed in 1.9
QgsColorButton::~QgsColorButton ( )

Member Function Documentation

bool QgsColorButton::acceptLiveUpdates ( )
inline

Whether the button accepts live updates from QColorDialog.

Note
added in 1.9
void QgsColorButton::changeEvent ( QEvent *  e)
protected
QColor QgsColorButton::color ( ) const

Return the currently selected color.

Returns
the currently selected color
Note
added in 1.9
void QgsColorButton::colorChanged ( const QColor &  color)
signal

Is emitted, whenever a new color is accepted.

The color is always valid. In case the new color is the same, no signal is emitted, to avoid infinite loops.

Parameters
colorNew color
Note
added in 1.9
QColorDialog::ColorDialogOptions QgsColorButton::colorDialogOptions ( )

Returns the options for the color chooser dialog.

Returns
Options for the color chooser dialog
Note
added in 1.9
QString QgsColorButton::colorDialogTitle ( )

Returns the title, which the color chooser dialog shows.

Returns
Title for the color chooser dialog
Note
added in 1.9
void QgsColorButton::dragEnterEvent ( QDragEnterEvent *  e)
protected

Reimplemented to accept dragged colors.

void QgsColorButton::dropEvent ( QDropEvent *  e)
protected

Reimplemented to accept dropped colors.

void QgsColorButton::keyPressEvent ( QKeyEvent *  e)
protected

Reimplemented to allow cancelling color pick via keypress, and sample via space bar press.

void QgsColorButton::mouseMoveEvent ( QMouseEvent *  e)
protected

Reimplemented to allow dragging colors from button.

void QgsColorButton::mousePressEvent ( QMouseEvent *  e)
protected

Reimplemented to detect right mouse button clicks on the color button and allow dragging colors.

void QgsColorButton::mouseReleaseEvent ( QMouseEvent *  e)
protected

Reimplemented to allow color picking.

void QgsColorButton::setAcceptLiveUpdates ( bool  accept)
inline

Sets whether the button accepts live updates from QColorDialog.

Live updates may cause changes that are not undoable on QColorDialog cancel.

Note
added in 1.9
void QgsColorButton::setButtonBackground ( QColor  color = QColor())
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

Parameters
colorColor for button background
Note
added in 1.9
void QgsColorButton::setColor ( const QColor &  color)

Specify the current color.

Will emit a colorChanged signal if the color is different to the previous.

Parameters
colorthe new color
Note
added in 1.9
void QgsColorButton::setColorDialogOptions ( QColorDialog::ColorDialogOptions  cdo)

Specify the options for the color chooser dialog (e.g.

alpha).

Parameters
cdoOptions for the color chooser dialog
Note
added in 1.9
void QgsColorButton::setColorDialogTitle ( QString  cdt)

Set the title, which the color chooser dialog will show.

Parameters
cdtTitle for the color chooser dialog
Note
added in 1.9
void QgsColorButton::showEvent ( QShowEvent *  e)
protected
const QPixmap & QgsColorButton::transpBkgrd ( )
staticprotected

The documentation for this class was generated from the following files: