Qt 4.8
Public Types | Public Functions | Private Functions | Properties | Friends | Related Functions | List of all members
QPalette Class Reference

The QPalette class contains color groups for each widget state. More...

#include <qpalette.h>

Public Types

enum  ColorGroup {
  Active, Disabled, Inactive, NColorGroups,
  Current, All, Normal = Active
}
 
enum  ColorRole {
  WindowText, Button, Light, Midlight,
  Dark, Mid, Text, BrightText,
  ButtonText, Base, Window, Shadow,
  Highlight, HighlightedText, Link, LinkVisited,
  AlternateBase, NoRole, ToolTipBase, ToolTipText,
  NColorRoles = ToolTipText + 1, Foreground = WindowText, Background = Window
}
 The ColorRole enum defines the different symbolic color roles used in current GUIs. More...
 

Public Functions

const QBrushalternateBase () const
 Returns the alternate base brush of the current color group. More...
 
const QBrushbackground () const
 Use window() instead. More...
 
const QBrushbase () const
 Returns the base brush of the current color group. More...
 
const QBrushbrightText () const
 Returns the bright text foreground brush of the current color group. More...
 
const QBrushbrush (ColorGroup cg, ColorRole cr) const
 Returns the brush in the specified color group, used for the given color role. More...
 
const QBrushbrush (ColorRole cr) const
 Returns the brush that has been set for the given color role in the current ColorGroup. More...
 
const QBrushbutton () const
 Returns the button brush of the current color group. More...
 
const QBrushbuttonText () const
 Returns the button text foreground brush of the current color group. More...
 
qint64 cacheKey () const
 Returns a number that identifies the contents of this QPalette object. More...
 
const QColorcolor (ColorGroup cg, ColorRole cr) const
 Returns the color in the specified color group, used for the given color role. More...
 
const QColorcolor (ColorRole cr) const
 Returns the color that has been set for the given color role in the current ColorGroup. More...
 
ColorGroup currentColorGroup () const
 Returns the palette's current color group. More...
 
const QBrushdark () const
 Returns the dark brush of the current color group. More...
 
const QBrushforeground () const
 Use windowText() instead. More...
 
const QBrushhighlight () const
 Returns the highlight brush of the current color group. More...
 
const QBrushhighlightedText () const
 Returns the highlighted text brush of the current color group. More...
 
bool isBrushSet (ColorGroup cg, ColorRole cr) const
 Returns true if the ColorGroup cg and ColorRole cr has been set previously on this palette; otherwise returns false. More...
 
bool isCopyOf (const QPalette &p) const
 Returns true if this palette and p are copies of each other, i.e. More...
 
bool isEqual (ColorGroup cr1, ColorGroup cr2) const
 Returns true (usually quickly) if color group cg1 is equal to cg2; otherwise returns false. More...
 
const QBrushlight () const
 Returns the light brush of the current color group. More...
 
const QBrushlink () const
 Returns the unvisited link text brush of the current color group. More...
 
const QBrushlinkVisited () const
 Returns the visited link text brush of the current color group. More...
 
const QBrushmid () const
 Returns the mid brush of the current color group. More...
 
const QBrushmidlight () const
 Returns the midlight brush of the current color group. More...
 
 operator QVariant () const
 Returns the palette as a QVariant. More...
 
bool operator!= (const QPalette &p) const
 Returns true (slowly) if this palette is different from p; otherwise returns false (usually quickly). More...
 
QPaletteoperator= (const QPalette &palette)
 Assigns p to this palette and returns a reference to this palette. More...
 
bool operator== (const QPalette &p) const
 Returns true (usually quickly) if this palette is equal to p; otherwise returns false (slowly). More...
 
 QPalette ()
 Constructs a palette object that uses the application's default palette. More...
 
 QPalette (const QColor &button)
 Constructs a palette from the button color. More...
 
 QPalette (Qt::GlobalColor button)
 Constructs a palette from the button color. More...
 
 QPalette (const QColor &button, const QColor &window)
 Constructs a palette from a button color and a window. More...
 
 QPalette (const QBrush &windowText, const QBrush &button, const QBrush &light, const QBrush &dark, const QBrush &mid, const QBrush &text, const QBrush &bright_text, const QBrush &base, const QBrush &window)
 Constructs a palette. More...
 
 QPalette (const QColor &windowText, const QColor &window, const QColor &light, const QColor &dark, const QColor &mid, const QColor &text, const QColor &base)
 
 QPalette (const QPalette &palette)
 Constructs a copy of p. More...
 
QPalette resolve (const QPalette &) const
 Returns a new QPalette that has attributes copied from other. More...
 
uint resolve () const
 
void resolve (uint mask)
 
int serialNumber () const
 Returns a number that identifies the contents of this QPalette object. More...
 
void setBrush (ColorRole cr, const QBrush &brush)
 Sets the brush for the given color role to the specified brush for all groups in the palette. More...
 
void setBrush (ColorGroup cg, ColorRole cr, const QBrush &brush)
 Sets the brush in the specified color group, used for the given color role, to brush. More...
 
void setColor (ColorGroup cg, ColorRole cr, const QColor &color)
 Sets the color in the specified color group, used for the given color role, to the specified solid color. More...
 
void setColor (ColorRole cr, const QColor &color)
 Sets the color used for the given color role, in all color groups, to the specified solid color. More...
 
void setColorGroup (ColorGroup cr, const QBrush &windowText, const QBrush &button, const QBrush &light, const QBrush &dark, const QBrush &mid, const QBrush &text, const QBrush &bright_text, const QBrush &base, const QBrush &window)
 Sets a the group at cg. More...
 
void setCurrentColorGroup (ColorGroup cg)
 Set the palette's current color group to cg. More...
 
const QBrushshadow () const
 Returns the shadow brush of the current color group. More...
 
const QBrushtext () const
 Returns the text foreground brush of the current color group. More...
 
const QBrushtoolTipBase () const
 Returns the tool tip base brush of the current color group. More...
 
const QBrushtoolTipText () const
 Returns the tool tip text brush of the current color group. More...
 
const QBrushwindow () const
 Returns the window (general background) brush of the current color group. More...
 
const QBrushwindowText () const
 Returns the window text (general foreground) brush of the current color group. More...
 
 ~QPalette ()
 Destroys the palette. More...
 

Private Functions

void detach ()
 
void init ()
 
void setColorGroup (ColorGroup cr, const QBrush &windowText, const QBrush &button, const QBrush &light, const QBrush &dark, const QBrush &mid, const QBrush &text, const QBrush &bright_text, const QBrush &base, const QBrush &alternate_base, const QBrush &window, const QBrush &midlight, const QBrush &button_text, const QBrush &shadow, const QBrush &highlight, const QBrush &highlighted_text, const QBrush &link, const QBrush &link_visited)
 
void setColorGroup (ColorGroup cr, const QBrush &windowText, const QBrush &button, const QBrush &light, const QBrush &dark, const QBrush &mid, const QBrush &text, const QBrush &bright_text, const QBrush &base, const QBrush &alternate_base, const QBrush &window, const QBrush &midlight, const QBrush &button_text, const QBrush &shadow, const QBrush &highlight, const QBrush &highlighted_text, const QBrush &link, const QBrush &link_visited, const QBrush &toolTipBase, const QBrush &toolTipText)
 

Properties

uint current_group: 4
 
QPalettePrivated
 
uint resolve_mask: 28
 

Friends

Q_GUI_EXPORT QDataStreamoperator<< (QDataStream &s, const QPalette &p)
 Writes the palette, p to the stream s and returns a reference to the stream. More...
 

Related Functions

(Note that these are not member functions.)

QDataStreamoperator>> (QDataStream &s, QPalette &p)
 Reads a palette from the stream, s into the palette p, and returns a reference to the stream. More...
 

Detailed Description

The QPalette class contains color groups for each widget state.

A palette consists of three color groups: Active, Disabled, and Inactive. All widgets in Qt contain a palette and use their palette to draw themselves. This makes the user interface easily configurable and easier to keep consistent.

If you create a new widget we strongly recommend that you use the colors in the palette rather than hard-coding specific colors.

The color groups:

Both active and inactive windows can contain disabled widgets. (Disabled widgets are often called inaccessible or grayed out.)

In most styles, Active and Inactive look the same.

Colors and brushes can be set for particular roles in any of a palette's color groups with setColor() and setBrush(). A color group contains a group of colors used by widgets for drawing themselves. We recommend that widgets use color group roles from the palette such as "foreground" and "base" rather than literal colors like "red" or "turquoise". The color roles are enumerated and defined in the ColorRole documentation.

We strongly recommend that you use the default palette of the current style (returned by QApplication::palette()) and modify that as necessary. This is done by Qt's widgets when they are drawn.

To modify a color group you call the functions setColor() and setBrush(), depending on whether you want a pure color or a pixmap pattern.

There are also corresponding color() and brush() getters, and a commonly used convenience function to get the ColorRole for the current ColorGroup: window(), windowText(), base(), etc.

You can copy a palette using the copy constructor and test to see if two palettes are identical using isCopyOf().

QPalette is optimized by the use of implicit sharing, so it is very efficient to pass QPalette objects as arguments.

Warning
Some styles do not use the palette for all drawing, for instance, if they make use of native theme engines. This is the case for both the Windows XP, Windows Vista, and the Mac OS X styles.
See also
QApplication::setPalette(), QWidget::setPalette(), QColor

Definition at line 61 of file qpalette.h.

Enumerations

◆ ColorGroup

  • Disabled
  • Active
  • Inactive
  • Normal synonym for Active
  • All
  • NColorGroups
  • Current
Enumerator
Active 
Disabled 
Inactive 
NColorGroups 
Current 
All 
Normal 

Definition at line 92 of file qpalette.h.

◆ ColorRole

The ColorRole enum defines the different symbolic color roles used in current GUIs.

palette.png
Color Roles

The central roles are:

  • Window A general background color.
  • Background This value is obsolete. Use Window instead.
  • WindowText A general foreground color.
  • Foreground This value is obsolete. Use WindowText instead.
  • Base Used mostly as the background color for text entry widgets, but can also be used for other painting - such as the background of combobox drop down lists and toolbar handles. It is usually white or another light color.
  • ToolTipBase Used as the background color for QToolTip and QWhatsThis. Tool tips use the Inactive color group of QPalette, because tool tips are not active windows.
  • ToolTipText Used as the foreground color for QToolTip and QWhatsThis. Tool tips use the Inactive color group of QPalette, because tool tips are not active windows.
  • Text The foreground color used with Base. This is usually the same as the WindowText, in which case it must provide good contrast with Window and Base.
  • Button The general button background color. This background can be different from Window as some styles require a different background color for buttons.
  • ButtonText A foreground color used with the Button color.
  • BrightText A text color that is very different from WindowText, and contrasts well with e.g. Dark. Typically used for text that needs to be drawn where Text or WindowText would give poor contrast, such as on pressed push buttons. Note that text colors can be used for things other than just words; text colors are usually used for text, but it's quite common to use the text color roles for lines, icons, etc.

There are some color roles used mostly for 3D bevel and shadow effects. All of these are normally derived from Window, and used in ways that depend on that relationship. For example, buttons depend on it to make the bevels look attractive, and Motif scroll bars depend on Mid to be slightly different from Window.

  • Light Lighter than Button color.
  • Midlight Between Button and Light.
  • Dark Darker than Button.
  • Mid Between Button and Dark.
  • Shadow A very dark color. By default, the shadow color is Qt::black.

Selected (marked) items have two roles:

  • Highlight A color to indicate a selected item or the current item. By default, the highlight color is Qt::darkBlue.
  • HighlightedText A text color that contrasts with Highlight. By default, the highlighted text color is Qt::white.

There are two color roles related to hyperlinks:

  • Link A text color used for unvisited hyperlinks. By default, the link color is Qt::blue.
  • LinkVisited A text color used for already visited hyperlinks. By default, the linkvisited color is Qt::magenta.

Note that we do not use the Link and LinkVisited roles when rendering rich text in Qt, and that we recommend that you use CSS and the QTextDocument::setDefaultStyleSheet() function to alter the appearance of links. For example:

QTextBrowser browser;
QColor linkColor(Qt::red);
QString sheet = QString::fromLatin1("a { text-decoration: underline; color: %1 }").arg(linkColor.name());
browser.document()->setDefaultStyleSheet(sheet);
  • NoRole No role; this special role is often used to indicate that a role has not been assigned.
  • NColorRoles
Enumerator
WindowText 
Button 
Light 
Midlight 
Dark 
Mid 
Text 
BrightText 
ButtonText 
Base 
Window 
Shadow 
Highlight 
HighlightedText 
Link 
LinkVisited 
AlternateBase 
NoRole 
ToolTipBase 
ToolTipText 
NColorRoles 
Foreground 
Background 

Definition at line 93 of file qpalette.h.

Constructors and Destructors

◆ QPalette() [1/7]

QPalette::QPalette ( )

Constructs a palette object that uses the application's default palette.

See also
QApplication::setPalette(), QApplication::palette()

Definition at line 673 of file qpalette.cpp.

Referenced by operator>>(), qt_mix_colors(), and setBrush().

676  resolve_mask(0)
677 {
678  d->ref.ref();
679 }
QPalettePrivate * d
Definition: qpalette.h:195
static QPalette palette()
Returns the application palette.
bool ref()
Atomically increments the value of this QAtomicInt.
QAtomicInt ref
Definition: qpalette.cpp:54
uint current_group
Definition: qpalette.h:196
uint resolve_mask
Definition: qpalette.h:197

◆ QPalette() [2/7]

QPalette::QPalette ( const QColor button)

Constructs a palette from the button color.

The other colors are automatically calculated, based on this color. Window will be the button color as well.

Definition at line 713 of file qpalette.cpp.

714 {
715  init();
716  qt_palette_from_color(*this, button);
717 }
void init()
Definition: qpalette.cpp:820
static void qt_palette_from_color(QPalette &pal, const QColor &button)
Definition: qpalette.cpp:681

◆ QPalette() [3/7]

QPalette::QPalette ( Qt::GlobalColor  button)

Constructs a palette from the button color.

The other colors are automatically calculated, based on this color. Window will be the button color as well.

Definition at line 724 of file qpalette.cpp.

725 {
726  init();
728 }
void init()
Definition: qpalette.cpp:820
static void qt_palette_from_color(QPalette &pal, const QColor &button)
Definition: qpalette.cpp:681
const QBrush & button() const
Returns the button brush of the current color group.
Definition: qpalette.h:125

◆ QPalette() [4/7]

QPalette::QPalette ( const QColor button,
const QColor window 
)

Constructs a palette from a button color and a window.

The other colors are automatically calculated, based on these colors.

Definition at line 770 of file qpalette.cpp.

771 {
772  init();
773  QColor bg = window, btn = button, fg, base, disfg;
774  int h, s, v;
775  bg.getHsv(&h, &s, &v);
776  if(v > 128) {
777  fg = Qt::black;
778  base = Qt::white;
779  disfg = Qt::darkGray;
780  } else {
781  fg = Qt::white;
782  base = Qt::black;
783  disfg = Qt::darkGray;
784  }
785  //inactive and active are identical
786  setColorGroup(Inactive, QBrush(fg), QBrush(btn), QBrush(btn.lighter(150)), QBrush(btn.darker()),
787  QBrush(btn.darker(150)), QBrush(fg), QBrush(Qt::white), QBrush(base),
788  QBrush(bg));
789  setColorGroup(Active, QBrush(fg), QBrush(btn), QBrush(btn.lighter(150)), QBrush(btn.darker()),
790  QBrush(btn.darker(150)), QBrush(fg), QBrush(Qt::white), QBrush(base),
791  QBrush(bg));
792  setColorGroup(Disabled, QBrush(disfg), QBrush(btn), QBrush(btn.lighter(150)),
793  QBrush(btn.darker()), QBrush(btn.darker(150)), QBrush(disfg),
794  QBrush(Qt::white), QBrush(base), QBrush(bg));
795 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
const QBrush & base() const
Returns the base brush of the current color group.
Definition: qpalette.h:130
void init()
Definition: qpalette.cpp:820
void getHsv(int *h, int *s, int *v, int *a=0) const
Sets the contents pointed to by h, s, v, and a, to the hue, saturation, value, and alpha-channel (tra...
Definition: qcolor.cpp:679
void setColorGroup(ColorGroup cr, const QBrush &windowText, const QBrush &button, const QBrush &light, const QBrush &dark, const QBrush &mid, const QBrush &text, const QBrush &bright_text, const QBrush &base, const QBrush &window)
Sets a the group at cg.
Definition: qpalette.cpp:1246
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
const QBrush & button() const
Returns the button brush of the current color group.
Definition: qpalette.h:125
const QBrush & window() const
Returns the window (general background) brush of the current color group.
Definition: qpalette.h:135

◆ QPalette() [5/7]

QPalette::QPalette ( const QBrush windowText,
const QBrush button,
const QBrush light,
const QBrush dark,
const QBrush mid,
const QBrush text,
const QBrush bright_text,
const QBrush base,
const QBrush window 
)

Constructs a palette.

You can pass either brushes, pixmaps or plain colors for windowText, button, light, dark, mid, text, bright_text, base and window.

See also
QBrush

Definition at line 737 of file qpalette.cpp.

742 {
743  init();
744  setColorGroup(All, windowText, button, light, dark, mid, text, bright_text,
745  base, window);
746 }
void init()
Definition: qpalette.cpp:820
void setColorGroup(ColorGroup cr, const QBrush &windowText, const QBrush &button, const QBrush &light, const QBrush &dark, const QBrush &mid, const QBrush &text, const QBrush &bright_text, const QBrush &base, const QBrush &window)
Sets a the group at cg.
Definition: qpalette.cpp:1246

◆ QPalette() [6/7]

QPalette::QPalette ( const QColor windowText,
const QColor window,
const QColor light,
const QColor dark,
const QColor mid,
const QColor text,
const QColor base 
)

Constructs a palette with the specified windowText, window, light, dark, mid, text, and base colors. The button color will be set to the window color.

Definition at line 755 of file qpalette.cpp.

758 {
759  init();
760  setColorGroup(All, QBrush(windowText), QBrush(window), QBrush(light),
761  QBrush(dark), QBrush(mid), QBrush(text), QBrush(light),
762  QBrush(base), QBrush(window));
763 }
void init()
Definition: qpalette.cpp:820
void setColorGroup(ColorGroup cr, const QBrush &windowText, const QBrush &button, const QBrush &light, const QBrush &dark, const QBrush &mid, const QBrush &text, const QBrush &bright_text, const QBrush &base, const QBrush &window)
Sets a the group at cg.
Definition: qpalette.cpp:1246
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76

◆ QPalette() [7/7]

QPalette::QPalette ( const QPalette p)

Constructs a copy of p.

This constructor is fast thanks to implicit sharing.

Definition at line 802 of file qpalette.cpp.

803 {
804  d = p.d;
805  d->ref.ref();
808 }
QPalettePrivate * d
Definition: qpalette.h:195
bool ref()
Atomically increments the value of this QAtomicInt.
QAtomicInt ref
Definition: qpalette.cpp:54
uint current_group
Definition: qpalette.h:196
uint resolve_mask
Definition: qpalette.h:197

◆ ~QPalette()

QPalette::~QPalette ( )

Destroys the palette.

Definition at line 813 of file qpalette.cpp.

814 {
815  if(!d->ref.deref())
816  delete d;
817 }
QPalettePrivate * d
Definition: qpalette.h:195
QAtomicInt ref
Definition: qpalette.cpp:54
bool deref()
Atomically decrements the value of this QAtomicInt.

Functions

◆ alternateBase()

const QBrush & QPalette::alternateBase ( ) const
inline

Returns the alternate base brush of the current color group.

See also
ColorRole brush()

Definition at line 131 of file qpalette.h.

Referenced by QWindowsVistaStyle::drawPrimitive().

131 { return brush(AlternateBase); }
const QBrush & brush(ColorGroup cg, ColorRole cr) const
Returns the brush in the specified color group, used for the given color role.
Definition: qpalette.cpp:874

◆ background()

const QBrush & QPalette::background ( ) const
inline

◆ base()

const QBrush & QPalette::base ( ) const
inline

◆ brightText()

const QBrush & QPalette::brightText ( ) const
inline

Returns the bright text foreground brush of the current color group.

See also
ColorRole brush()

Definition at line 137 of file qpalette.h.

Referenced by QWindowsCEStyle::drawPrimitive(), qt_set_windows_color_resources(), and setBrush().

137 { return brush(BrightText); }
const QBrush & brush(ColorGroup cg, ColorRole cr) const
Returns the brush in the specified color group, used for the given color role.
Definition: qpalette.cpp:874

◆ brush() [1/2]

const QBrush & QPalette::brush ( ColorGroup  group,
ColorRole  role 
) const

Returns the brush in the specified color group, used for the given color role.

See also
color() setBrush() ColorRole

Definition at line 874 of file qpalette.cpp.

Referenced by QLineControl::draw(), QItemDelegate::drawBackground(), QWindowsCEStyle::drawComplexControl(), QCommonStyle::drawComplexControl(), QWindowsMobileStyle::drawComplexControl(), QWindowsStyle::drawComplexControl(), QMotifStyle::drawComplexControl(), QWindowsCEStyle::drawControl(), QCommonStyle::drawControl(), QCDEStyle::drawControl(), QWindowsMobileStyle::drawControl(), QPlastiqueStyle::drawControl(), QCleanlooksStyle::drawControl(), QWindowsStyle::drawControl(), QGtkStyle::drawControl(), QMotifStyle::drawControl(), QStyleSheetStyle::drawControl(), QItemDelegate::drawDisplay(), QCleanlooksStyle::drawItemText(), QStyle::drawItemText(), QTextDocumentLayoutPrivate::drawListItem(), QWindowsMobileStylePrivate::drawPanelItemViewSelected(), QWindowsCEStyle::drawPrimitive(), QCommonStyle::drawPrimitive(), QWindowsVistaStyle::drawPrimitive(), QWindowsMobileStyle::drawPrimitive(), QPlastiqueStyle::drawPrimitive(), QCDEStyle::drawPrimitive(), QWindowsXPStyle::drawPrimitive(), QWindowsStyle::drawPrimitive(), QMotifStyle::drawPrimitive(), QMacStyle::drawPrimitive(), QStyleSheetStyle::drawPrimitive(), QCalendarModel::formatForCell(), QTextControl::getPaintContext(), QPainter::initFrom(), QApplicationPrivate::initializeWidgetPaletteHash(), QWidgetPrivate::isBackgroundInherited(), QDecorationDefault::paint(), QDecorationWindows::paintButton(), QDecorationDefault::paintButton(), QGraphicsView::paintEvent(), QMotifStyle::polish(), qDrawPlainRect(), qt_mac_display_change_callbk(), QWidget::testAttribute(), QDirectFBWindowSurface::updateIsOpaque(), and QWidgetPrivate::updateIsOpaque().

875 {
876  Q_ASSERT(cr < NColorRoles);
877  if(gr >= (int)NColorGroups) {
878  if(gr == Current) {
880  } else {
881  qWarning("QPalette::brush: Unknown ColorGroup: %d", (int)gr);
882  gr = Active;
883  }
884  }
885  return d->br[gr][cr];
886 }
QPalettePrivate * d
Definition: qpalette.h:195
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
ColorGroup
Definition: qpalette.h:92
Q_CORE_EXPORT void qWarning(const char *,...)
uint current_group
Definition: qpalette.h:196
QBrush br[QPalette::NColorGroups][QPalette::NColorRoles]
Definition: qpalette.cpp:55

◆ brush() [2/2]

const QBrush & QPalette::brush ( ColorRole  role) const
inline

Returns the brush that has been set for the given color role in the current ColorGroup.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

See also
color() setBrush() ColorRole

Definition at line 122 of file qpalette.h.

Referenced by brush().

122 { return brush(Current, cr); }
const QBrush & brush(ColorGroup cg, ColorRole cr) const
Returns the brush in the specified color group, used for the given color role.
Definition: qpalette.cpp:874

◆ button()

const QBrush & QPalette::button ( ) const
inline

Returns the button brush of the current color group.

See also
ColorRole brush()

Definition at line 125 of file qpalette.h.

Referenced by QCommonStyle::drawComplexControl(), QWindowsCEStyle::drawComplexControl(), QPlastiqueStyle::drawComplexControl(), QWindowsMobileStyle::drawComplexControl(), QCleanlooksStyle::drawComplexControl(), QWindowsStyle::drawComplexControl(), QGtkStyle::drawComplexControl(), QMotifStyle::drawComplexControl(), QWindowsCEStyle::drawControl(), QPlastiqueStyle::drawControl(), QWindowsMobileStyle::drawControl(), QCleanlooksStyle::drawControl(), QWindowsStyle::drawControl(), QMotifStyle::drawControl(), QStyleHelper::drawDial(), QWindowsCEStyle::drawPrimitive(), QWindowsMobileStyle::drawPrimitive(), QPlastiqueStyle::drawPrimitive(), QCleanlooksStyle::drawPrimitive(), QWindowsStyle::drawPrimitive(), QMotifStyle::drawPrimitive(), QWindowsMobileStylePrivate::drawScrollbarGrip(), QWindowsMobileStylePrivate::drawScrollbarGroove(), QWindowsMobileStylePrivate::drawScrollbarHandleDown(), QWindowsMobileStylePrivate::drawScrollbarHandleUp(), QWindowsMobileStylePrivate::drawTabBarTab(), QWindowsCEStylePrivate::drawWinCEButton(), QWindowsCEStylePrivate::drawWinCEPanel(), QWindowsMobileStyle::polish(), qDrawPlainRect(), qDrawWinButton(), QPalette(), qt_cleanlooks_draw_mdibutton(), qt_palette_from_color(), qt_plastique_drawFrame(), qt_plastique_drawShadedPanel(), qt_set_windows_color_resources(), and setBrush().

125 { return brush(Button); }
const QBrush & brush(ColorGroup cg, ColorRole cr) const
Returns the brush in the specified color group, used for the given color role.
Definition: qpalette.cpp:874
Button
Definition: qmessagebox.cpp:82

◆ buttonText()

const QBrush & QPalette::buttonText ( ) const
inline

Returns the button text foreground brush of the current color group.

See also
ColorRole brush()

Definition at line 138 of file qpalette.h.

Referenced by QPlastiqueStyle::drawComplexControl(), QMotifStyle::drawComplexControl(), QPlastiqueStyle::drawControl(), QGtkStyle::drawControl(), QMotifStyle::drawControl(), QStyleSheetStyle::drawControl(), QWindowsCEStyle::drawPrimitive(), QCommonStyle::drawPrimitive(), QWindowsMobileStyle::drawPrimitive(), QWindowsStyle::drawPrimitive(), QGtkStyle::drawPrimitive(), QCommandLinkButton::paintEvent(), and setBrush().

138 { return brush(ButtonText); }
const QBrush & brush(ColorGroup cg, ColorRole cr) const
Returns the brush in the specified color group, used for the given color role.
Definition: qpalette.cpp:874

◆ cacheKey()

qint64 QPalette::cacheKey ( ) const

Returns a number that identifies the contents of this QPalette object.

Distinct QPalette objects can have the same key if they refer to the same contents.

The cacheKey() will change when the palette is altered.

Definition at line 1093 of file qpalette.cpp.

Referenced by QPixmapIconEngine::pixmap(), and QStyleHelper::uniqueName().

1094 {
1095  return (((qint64) d->ser_no) << 32) | ((qint64) (d->detach_no));
1096 }
QPalettePrivate * d
Definition: qpalette.h:195
__int64 qint64
Definition: qglobal.h:942

◆ color() [1/2]

const QColor & QPalette::color ( ColorGroup  group,
ColorRole  role 
) const
inline

Returns the color in the specified color group, used for the given color role.

See also
brush() setColor() ColorRole

Definition at line 107 of file qpalette.h.

Referenced by brushFromData(), QCss::Declaration::brushValue(), QCss::Declaration::brushValues(), colorFromData(), QCss::Declaration::colorValue(), QCss::Declaration::colorValues(), QEgl::createSurface(), QGraphicsTextItem::defaultTextColor(), QMdiSubWindowPrivate::desktopPalette(), QTextDocumentLayoutPrivate::drawBlock(), QPlastiqueStyle::drawComplexControl(), QCleanlooksStyle::drawComplexControl(), QGtkStyle::drawComplexControl(), QWindowsVistaStyle::drawControl(), QCommonStyle::drawControl(), QCDEStyle::drawControl(), QPlastiqueStyle::drawControl(), QCleanlooksStyle::drawControl(), QWindowsXPStyle::drawControl(), QMacStyle::drawControl(), QItemDelegate::drawDisplay(), QItemDelegate::drawFocus(), QTextDocumentLayoutPrivate::drawFrame(), QWindowsCEStyle::drawItemText(), QPlastiqueStyle::drawPrimitive(), QTreeView::drawRow(), QLCDNumberPrivate::drawSegment(), QScriptEdit::extraAreaPaintEvent(), QCommonStyle::generatedIconPixmap(), QDeclarativeTextEditPrivate::init(), QDeclarativeTextInputPrivate::init(), QApplicationPrivate::initializeWidgetPaletteHash(), QAxClientSite::Invoke(), QAccessibleWidgetEx::invokeMethodEx(), QApplication::isLeftToRight(), QDecorationWindows::paint(), QDecorationStyled::paint(), QDecorationDefault::paint(), QDecorationWindows::paintButton(), QLabel::paintEvent(), QCalToolButton::paintEvent(), QmlJSDebugger::ColorPickerTool::pickColor(), QMotifStyle::polish(), qDrawShadeLine(), QRenderRule::QRenderRule(), qt_plastique_draw_handle(), qt_plastique_drawFrame(), qt_set_windows_color_resources(), QWorkspaceTitleBarPrivate::readColors(), QItemDelegate::selected(), setBrush(), QGraphicsTextItem::setDefaultTextColor(), QApplicationPrivate::setSystemPalette(), QPlastiqueStyle::standardPalette(), QMotifStyle::standardPixmap(), QCommonStyle::styleHint(), QWindowsVistaStyle::styleHint(), QWidget::testAttribute(), and QToolBoxPrivate::updateTabs().

108  { return brush(cg, cr).color(); }
const QColor & color() const
Returns the brush color.
Definition: qbrush.h:183
const QBrush & brush(ColorGroup cg, ColorRole cr) const
Returns the brush in the specified color group, used for the given color role.
Definition: qpalette.cpp:874

◆ color() [2/2]

const QColor & QPalette::color ( ColorRole  role) const
inline

Returns the color that has been set for the given color role in the current ColorGroup.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

See also
brush() ColorRole

Definition at line 121 of file qpalette.h.

Referenced by color().

121 { return color(Current, cr); }
const QColor & color(ColorGroup cg, ColorRole cr) const
Returns the color in the specified color group, used for the given color role.
Definition: qpalette.h:107

◆ currentColorGroup()

ColorGroup QPalette::currentColorGroup ( ) const
inline

Returns the palette's current color group.

Definition at line 104 of file qpalette.h.

Referenced by QCleanlooksStyle::drawControl(), QMacStyle::drawPrimitive(), QMacStylePrivate::initComboboxBdi(), QMacStylePrivate::initHIThemePushButton(), and QLineEdit::paintEvent().

104 { return static_cast<ColorGroup>(current_group); }
ColorGroup
Definition: qpalette.h:92
uint current_group
Definition: qpalette.h:196

◆ dark()

const QBrush & QPalette::dark ( ) const
inline

◆ detach()

void QPalette::detach ( )
private
Warning
This function is not part of the public interface.

Definition at line 953 of file qpalette.cpp.

Referenced by linkVisited(), resolve(), setBrush(), and setColorGroup().

954 {
955  if (d->ref != 1) {
957  for(int grp = 0; grp < (int)NColorGroups; grp++) {
958  for(int role = 0; role < (int)NColorRoles; role++)
959  x->br[grp][role] = d->br[grp][role];
960  }
961  if(!d->ref.deref())
962  delete d;
963  d = x;
964  }
965  ++d->detach_no;
966 }
QPalettePrivate * d
Definition: qpalette.h:195
QAtomicInt ref
Definition: qpalette.cpp:54
bool deref()
Atomically decrements the value of this QAtomicInt.
QBrush br[QPalette::NColorGroups][QPalette::NColorRoles]
Definition: qpalette.cpp:55

◆ foreground()

const QBrush & QPalette::foreground ( ) const
inline

Use windowText() instead.

Definition at line 123 of file qpalette.h.

Referenced by QCommonStyle::drawComplexControl(), QCommonStyle::drawControl(), QMotifStyle::drawControl(), QCommonStyle::drawPrimitive(), QCDEStyle::drawPrimitive(), QColorLuminancePicker::paintEvent(), qDrawPlainRect(), qt_set_windows_color_resources(), and setBrush().

123 { return brush(WindowText); }
const QBrush & brush(ColorGroup cg, ColorRole cr) const
Returns the brush in the specified color group, used for the given color role.
Definition: qpalette.cpp:874

◆ highlight()

const QBrush & QPalette::highlight ( ) const
inline

◆ highlightedText()

const QBrush & QPalette::highlightedText ( ) const
inline

◆ init()

void QPalette::init ( )
private
Warning
This function is not part of the public interface.

Definition at line 820 of file qpalette.cpp.

Referenced by QPalette().

820  {
821  d = new QPalettePrivate;
822  resolve_mask = 0;
823  current_group = Active; //as a default..
824 }
QPalettePrivate * d
Definition: qpalette.h:195
uint current_group
Definition: qpalette.h:196
uint resolve_mask
Definition: qpalette.h:197

◆ isBrushSet()

bool QPalette::isBrushSet ( ColorGroup  cg,
ColorRole  cr 
) const

Returns true if the ColorGroup cg and ColorRole cr has been set previously on this palette; otherwise returns false.

Since
4.2
See also
setBrush()

Definition at line 944 of file qpalette.cpp.

Referenced by QGroupBox::initStyleOption().

945 {
946  Q_UNUSED(cg);
947  return (resolve_mask & (1<<cr));
948 }
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
uint resolve_mask
Definition: qpalette.h:197

◆ isCopyOf()

bool QPalette::isCopyOf ( const QPalette p) const

Returns true if this palette and p are copies of each other, i.e.

one of them was created as a copy of the other and neither was subsequently modified; otherwise returns false. This is much stricter than equality.

See also
operator=() operator==()

Definition at line 1233 of file qpalette.cpp.

Referenced by QWidgetPrivate::naturalWidgetPalette(), operator==(), and QApplicationPrivate::setPalette_helper().

1234 {
1235  return d == p.d;
1236 }
QPalettePrivate * d
Definition: qpalette.h:195

◆ isEqual()

bool QPalette::isEqual ( QPalette::ColorGroup  group1,
QPalette::ColorGroup  group2 
) const

Returns true (usually quickly) if color group cg1 is equal to cg2; otherwise returns false.

Definition at line 1035 of file qpalette.cpp.

Referenced by QLineEdit::changeEvent(), and QWidget::event().

1036 {
1037  if(group1 >= (int)NColorGroups) {
1038  if(group1 == Current) {
1039  group1 = (ColorGroup)current_group;
1040  } else {
1041  qWarning("QPalette::brush: Unknown ColorGroup(1): %d", (int)group1);
1042  group1 = Active;
1043  }
1044  }
1045  if(group2 >= (int)NColorGroups) {
1046  if(group2 == Current) {
1047  group2 = (ColorGroup)current_group;
1048  } else {
1049  qWarning("QPalette::brush: Unknown ColorGroup(2): %d", (int)group2);
1050  group2 = Active;
1051  }
1052  }
1053  if(group1 == group2)
1054  return true;
1055  for(int role = 0; role < (int)NColorRoles; role++) {
1056  if(d->br[group1][role] != d->br[group2][role])
1057  return false;
1058  }
1059  return true;
1060 }
QPalettePrivate * d
Definition: qpalette.h:195
ColorGroup
Definition: qpalette.h:92
Q_CORE_EXPORT void qWarning(const char *,...)
uint current_group
Definition: qpalette.h:196
QBrush br[QPalette::NColorGroups][QPalette::NColorRoles]
Definition: qpalette.cpp:55

◆ light()

const QBrush & QPalette::light ( ) const
inline

Returns the light brush of the current color group.

See also
ColorRole brush()

Definition at line 126 of file qpalette.h.

Referenced by QCommonStyle::drawComplexControl(), QWindowsCEStyle::drawComplexControl(), QWindowsMobileStyle::drawComplexControl(), QCleanlooksStyle::drawComplexControl(), QWindowsStyle::drawComplexControl(), QWindowsXPStyle::drawComplexControl(), QMotifStyle::drawComplexControl(), QWindowsCEStyle::drawControl(), QCommonStyle::drawControl(), QWindowsMobileStyle::drawControl(), QPlastiqueStyle::drawControl(), QCleanlooksStyle::drawControl(), QWindowsStyle::drawControl(), QMotifStyle::drawControl(), QStyleSheetStyle::drawControl(), QWindowsCEStyle::drawItemText(), QStyle::drawItemText(), QWindowsCEStyle::drawPrimitive(), QCommonStyle::drawPrimitive(), QWindowsMobileStyle::drawPrimitive(), QPlastiqueStyle::drawPrimitive(), QCleanlooksStyle::drawPrimitive(), QCDEStyle::drawPrimitive(), QWindowsStyle::drawPrimitive(), QMotifStyle::drawPrimitive(), QMacStyle::drawPrimitive(), QWindowsMobileStylePrivate::drawScrollbarGroove(), QLCDNumberPrivate::drawSegment(), QWindowsMobileStylePrivate::drawTabBarTab(), QWindowsCEStylePrivate::drawWinCEButton(), QWindowsCEStylePrivate::drawWinCEPanel(), QLabel::paintEvent(), qDrawPlainRect(), qDrawShadeLine(), qDrawShadePanel(), qDrawShadeRect(), qDrawWinButton(), qDrawWinPanel(), qt_plastique_draw_handle(), qt_set_windows_color_resources(), and setBrush().

126 { return brush(Light); }
const QBrush & brush(ColorGroup cg, ColorRole cr) const
Returns the brush in the specified color group, used for the given color role.
Definition: qpalette.cpp:874

◆ link()

const QBrush & QPalette::link ( ) const
inline

Returns the unvisited link text brush of the current color group.

See also
ColorRole brush()

Definition at line 142 of file qpalette.h.

Referenced by QWindowsCEStyle::drawPrimitive(), and setBrush().

142 { return brush(Link); }
const QBrush & brush(ColorGroup cg, ColorRole cr) const
Returns the brush in the specified color group, used for the given color role.
Definition: qpalette.cpp:874

◆ linkVisited()

const QBrush & QPalette::linkVisited ( ) const
inline

Returns the visited link text brush of the current color group.

See also
ColorRole brush()

Definition at line 143 of file qpalette.h.

Referenced by setBrush().

143 { return brush(LinkVisited); }
const QBrush & brush(ColorGroup cg, ColorRole cr) const
Returns the brush in the specified color group, used for the given color role.
Definition: qpalette.cpp:874

◆ mid()

const QBrush & QPalette::mid ( ) const
inline

Returns the mid brush of the current color group.

See also
ColorRole brush()

Definition at line 128 of file qpalette.h.

Referenced by QCleanlooksStyle::drawComplexControl(), QWindowsCEStyle::drawPrimitive(), QWindowsMobileStyle::drawPrimitive(), QWindowsStyle::drawPrimitive(), QMotifStyle::drawPrimitive(), QWizardHeader::paintEvent(), qDrawPlainRect(), qDrawShadeLine(), qDrawShadeRect(), qt_set_windows_color_resources(), setBrush(), and QCleanlooksStyle::standardPalette().

128 { return brush(Mid); }
const QBrush & brush(ColorGroup cg, ColorRole cr) const
Returns the brush in the specified color group, used for the given color role.
Definition: qpalette.cpp:874

◆ midlight()

const QBrush & QPalette::midlight ( ) const
inline

Returns the midlight brush of the current color group.

See also
ColorRole brush()

Definition at line 136 of file qpalette.h.

Referenced by QWindowsCEStyle::drawComplexControl(), QWindowsCEStyle::drawPrimitive(), QWindowsStyle::drawPrimitive(), QWindowsCEStylePrivate::drawWinCEButton(), QWindowsCEStylePrivate::drawWinCEPanel(), qDrawShadePanel(), qDrawWinPanel(), qt_set_windows_color_resources(), and setBrush().

136 { return brush(Midlight); }
const QBrush & brush(ColorGroup cg, ColorRole cr) const
Returns the brush in the specified color group, used for the given color role.
Definition: qpalette.cpp:874

◆ operator QVariant()

QPalette::operator QVariant ( ) const

Returns the palette as a QVariant.

Definition at line 846 of file qpalette.cpp.

847 {
848  return QVariant(QVariant::Palette, this);
849 }
The QVariant class acts like a union for the most common Qt data types.
Definition: qvariant.h:92

◆ operator!=()

bool QPalette::operator!= ( const QPalette p) const
inline

Returns true (slowly) if this palette is different from p; otherwise returns false (usually quickly).

Note
The current ColorGroup is not taken into account when comparing palettes
See also
operator==()

Definition at line 159 of file qpalette.h.

Referenced by setBrush().

159 { return !(operator==(p)); }
bool operator==(const QPalette &p) const
Returns true (usually quickly) if this palette is equal to p; otherwise returns false (slowly)...
Definition: qpalette.cpp:992

◆ operator=()

QPalette & QPalette::operator= ( const QPalette p)

Assigns p to this palette and returns a reference to this palette.

This operation is fast thanks to implicit sharing.

Definition at line 832 of file qpalette.cpp.

833 {
834  p.d->ref.ref();
837  if(!d->ref.deref())
838  delete d;
839  d = p.d;
840  return *this;
841 }
QPalettePrivate * d
Definition: qpalette.h:195
bool ref()
Atomically increments the value of this QAtomicInt.
QAtomicInt ref
Definition: qpalette.cpp:54
bool deref()
Atomically decrements the value of this QAtomicInt.
uint current_group
Definition: qpalette.h:196
uint resolve_mask
Definition: qpalette.h:197

◆ operator==()

bool QPalette::operator== ( const QPalette p) const

Returns true (usually quickly) if this palette is equal to p; otherwise returns false (slowly).

Note
The current ColorGroup is not taken into account when comparing palettes
See also
operator!=()

Definition at line 992 of file qpalette.cpp.

Referenced by setBrush().

993 {
994  if (isCopyOf(p))
995  return true;
996  for(int grp = 0; grp < (int)NColorGroups; grp++) {
997  for(int role = 0; role < (int)NColorRoles; role++) {
998  if(d->br[grp][role] != p.d->br[grp][role])
999  return false;
1000  }
1001  }
1002  return true;
1003 }
QPalettePrivate * d
Definition: qpalette.h:195
bool isCopyOf(const QPalette &p) const
Returns true if this palette and p are copies of each other, i.e.
Definition: qpalette.cpp:1233
QBrush br[QPalette::NColorGroups][QPalette::NColorRoles]
Definition: qpalette.cpp:55

◆ resolve() [1/3]

QPalette QPalette::resolve ( const QPalette other) const

Returns a new QPalette that has attributes copied from other.

Definition at line 1101 of file qpalette.cpp.

Referenced by QGtkStyle::drawComplexControl(), QPlastiqueStyle::drawControl(), QGtkStyle::drawControl(), QGtkStyle::drawPrimitive(), QComboMenuDelegate::getStyleOption(), QGraphicsWidgetPrivate::naturalWidgetPalette(), QWidgetPrivate::naturalWidgetPalette(), QGtkStyle::polish(), QWidgetPrivate::propagatePaletteChange(), QGraphicsWidgetPrivate::resolvePalette(), QGraphicsScenePrivate::resolvePalette(), QWidgetPrivate::resolvePalette(), QGraphicsWidget::setPalette(), QGraphicsScene::setPalette(), QWidget::setPalette(), QGraphicsWidgetPrivate::setPalette_helper(), QGraphicsScenePrivate::setPalette_helper(), QWidgetPrivate::setPalette_helper(), QGraphicsWidgetPrivate::updatePalette(), and QGraphicsScenePrivate::updatePalette().

1102 {
1103  if ((*this == other && resolve_mask == other.resolve_mask)
1104  || resolve_mask == 0) {
1105  QPalette o = other;
1107  return o;
1108  }
1109 
1110  QPalette palette(*this);
1111  palette.detach();
1112 
1113  for(int role = 0; role < (int)NColorRoles; role++)
1114  if (!(resolve_mask & (1<<role)))
1115  for(int grp = 0; grp < (int)NColorGroups; grp++)
1116  palette.d->br[grp][role] = other.d->br[grp][role];
1117 
1118  return palette;
1119 }
QPalettePrivate * d
Definition: qpalette.h:195
QBrush br[QPalette::NColorGroups][QPalette::NColorRoles]
Definition: qpalette.cpp:55
uint resolve_mask
Definition: qpalette.h:197
The QPalette class contains color groups for each widget state.
Definition: qpalette.h:61

◆ resolve() [2/3]

uint QPalette::resolve ( ) const
inline
Warning
This function is not part of the public interface.

Definition at line 166 of file qpalette.h.

166 { return resolve_mask; }
uint resolve_mask
Definition: qpalette.h:197

◆ resolve() [3/3]

void QPalette::resolve ( uint  mask)
inline
Warning
This function is not part of the public interface.

Definition at line 167 of file qpalette.h.

167 { resolve_mask = mask; }
uint resolve_mask
Definition: qpalette.h:197

◆ serialNumber()

int QPalette::serialNumber ( ) const

Returns a number that identifies the contents of this QPalette object.

Distinct QPalette objects can only have the same serial number if they refer to the same contents (but they don't have to). Also, the serial number of a QPalette may change during the lifetime of the object.

Use cacheKey() instead.

Warning
The serial number doesn't necessarily change when the palette is altered. This means that it may be dangerous to use it as a cache key.
See also
operator==()

Definition at line 1081 of file qpalette.cpp.

1082 {
1083  return d->ser_no;
1084 }
QPalettePrivate * d
Definition: qpalette.h:195

◆ setBrush() [1/2]

void QPalette::setBrush ( ColorRole  role,
const QBrush brush 
)
inline

◆ setBrush() [2/2]

void QPalette::setBrush ( ColorGroup  group,
ColorRole  role,
const QBrush brush 
)

Sets the brush in the specified color group, used for the given color role, to brush.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

See also
brush() setColor() ColorRole

Definition at line 912 of file qpalette.cpp.

913 {
914  Q_ASSERT(cr < NColorRoles);
915  detach();
916  if(cg >= (int)NColorGroups) {
917  if(cg == All) {
918  for(int i = 0; i < (int)NColorGroups; i++)
919  d->br[i][cr] = b;
920  resolve_mask |= (1<<cr);
921  return;
922  } else if(cg == Current) {
924  } else {
925  qWarning("QPalette::setBrush: Unknown ColorGroup: %d", (int)cg);
926  cg = Active;
927  }
928  }
929  d->br[cg][cr] = b;
930  resolve_mask |= (1<<cr);
931 }
void detach()
Definition: qpalette.cpp:953
QPalettePrivate * d
Definition: qpalette.h:195
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
ColorGroup
Definition: qpalette.h:92
Q_CORE_EXPORT void qWarning(const char *,...)
uint current_group
Definition: qpalette.h:196
QBrush br[QPalette::NColorGroups][QPalette::NColorRoles]
Definition: qpalette.cpp:55
uint resolve_mask
Definition: qpalette.h:197

◆ setColor() [1/2]

void QPalette::setColor ( ColorGroup  group,
ColorRole  role,
const QColor color 
)
inline

Sets the color in the specified color group, used for the given color role, to the specified solid color.

See also
setBrush() color() ColorRole

Definition at line 201 of file qpalette.h.

Referenced by QMdiSubWindowPrivate::desktopPalette(), QWindowsCEStyle::drawComplexControl(), QWindowsStyle::drawComplexControl(), QStyleSheetStyle::drawComplexControl(), QWindowsCEStyle::drawControl(), QWindowsVistaStyle::drawControl(), QCommonStyle::drawControl(), QWindowsMobileStyle::drawControl(), QPlastiqueStyle::drawControl(), QCleanlooksStyle::drawControl(), QWindowsXPStyle::drawControl(), QWindowsStyle::drawControl(), QMotifStyle::drawControl(), QMacStyle::drawControl(), QStyleSheetStyle::drawControl(), QWindowsCEStyle::drawPrimitive(), QWindowsMobileStyle::drawPrimitive(), QWindowsStyle::drawPrimitive(), QDeclarativeTextEditPrivate::init(), QApplicationPrivate::initializeWidgetPaletteHash(), QTabBar::initStyleOption(), QApplication::isLeftToRight(), QAxServerBase::OnAmbientPropertyChange(), QDecorationStyled::paint(), QDeclarativeText::paint(), QCommandLinkButton::paintEvent(), QLabel::paintEvent(), QCalToolButton::paintEvent(), QStaticTextPrivate::paintText(), QMotifStyle::polish(), QMacStyle::polish(), QWindowsVistaStyle::polish(), QWindowsMobileStyle::polish(), printPage(), QBalloonTip::QBalloonTip(), QApplicationPrivate::qt_mac_apply_settings(), qt_mix_colors(), qt_set_windows_color_resources(), QWorkspaceTitleBarPrivate::readColors(), readV1ColorGroup(), QWizardPrivate::recreateLayout(), QDeclarativeTextEdit::setColor(), QGraphicsTextItem::setDefaultTextColor(), QScriptDebuggerCodeFinderWidget::setOK(), QDeclarativeTextInput::setSelectedTextColor(), QDeclarativeTextEdit::setSelectedTextColor(), QDeclarativeTextInput::setSelectionColor(), QDeclarativeTextEdit::setSelectionColor(), QApplicationPrivate::setSystemPalette(), QGtkStyle::standardPalette(), QWindowsCEStyle::standardPalette(), QMacStyle::standardPalette(), QWindowsMobileStyle::standardPalette(), QWidget::testAttribute(), QDeclarativeTextPrivate::textDocumentImage(), QToolBoxPrivate::updateTabs(), and QApplicationPrivate::x11_apply_settings().

203 { setBrush(acg, acr, QBrush(acolor)); }
void setBrush(ColorRole cr, const QBrush &brush)
Sets the brush for the given color role to the specified brush for all groups in the palette...
Definition: qpalette.h:206
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76

◆ setColor() [2/2]

void QPalette::setColor ( ColorRole  role,
const QColor color 
)
inline

Sets the color used for the given color role, in all color groups, to the specified solid color.

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

See also
brush() setColor() ColorRole

Definition at line 204 of file qpalette.h.

205 { setColor(All, acr, acolor); }
void setColor(ColorGroup cg, ColorRole cr, const QColor &color)
Sets the color in the specified color group, used for the given color role, to the specified solid co...
Definition: qpalette.h:201

◆ setColorGroup() [1/3]

void QPalette::setColorGroup ( ColorGroup  cg,
const QBrush windowText,
const QBrush button,
const QBrush light,
const QBrush dark,
const QBrush mid,
const QBrush text,
const QBrush bright_text,
const QBrush base,
const QBrush window 
)

Sets a the group at cg.

You can pass either brushes, pixmaps or plain colors for windowText, button, light, dark, mid, text, bright_text, base and window.

See also
QBrush

Definition at line 1246 of file qpalette.cpp.

Referenced by QPalette(), qt_mix_colors(), qt_palette_from_color(), qt_set_windows_color_resources(), and setColorGroup().

1250 {
1251  QBrush alt_base = QBrush(qt_mix_colors(base.color(), button.color()));
1252  QBrush mid_light = QBrush(qt_mix_colors(button.color(), light.color()));
1253  QColor toolTipBase(255, 255, 220);
1254  QColor toolTipText(0, 0, 0);
1255 
1256  setColorGroup(cg, windowText, button, light, dark, mid, text, bright_text, base,
1257  alt_base, window, mid_light, text,
1260  QBrush(toolTipText));
1261 
1262  resolve_mask &= ~(1 << Highlight);
1263  resolve_mask &= ~(1 << HighlightedText);
1264  resolve_mask &= ~(1 << LinkVisited);
1265  resolve_mask &= ~(1 << Link);
1266 }
The QColor class provides colors based on RGB, HSV or CMYK values.
Definition: qcolor.h:67
const QColor & color() const
Returns the brush color.
Definition: qbrush.h:183
static QColor qt_mix_colors(QColor a, QColor b)
Definition: qpalette.cpp:60
void setColorGroup(ColorGroup cr, const QBrush &windowText, const QBrush &button, const QBrush &light, const QBrush &dark, const QBrush &mid, const QBrush &text, const QBrush &bright_text, const QBrush &base, const QBrush &window)
Sets a the group at cg.
Definition: qpalette.cpp:1246
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
const QBrush & toolTipBase() const
Returns the tool tip base brush of the current color group.
Definition: qpalette.h:132
const QBrush & toolTipText() const
Returns the tool tip text brush of the current color group.
Definition: qpalette.h:133
uint resolve_mask
Definition: qpalette.h:197

◆ setColorGroup() [2/3]

void QPalette::setColorGroup ( ColorGroup  cg,
const QBrush foreground,
const QBrush button,
const QBrush light,
const QBrush dark,
const QBrush mid,
const QBrush text,
const QBrush bright_text,
const QBrush base,
const QBrush alternate_base,
const QBrush background,
const QBrush midlight,
const QBrush button_text,
const QBrush shadow,
const QBrush highlight,
const QBrush highlighted_text,
const QBrush link,
const QBrush link_visited 
)
private
Warning
This function is not part of the public interface.

Definition at line 1271 of file qpalette.cpp.

1279 {
1280  setColorGroup(cg, foreground, button, light, dark, mid,
1281  text, bright_text, base, alternate_base, background,
1282  midlight, button_text, shadow, highlight, highlighted_text,
1283  link, link_visited, background, foreground);
1284 }
void setColorGroup(ColorGroup cr, const QBrush &windowText, const QBrush &button, const QBrush &light, const QBrush &dark, const QBrush &mid, const QBrush &text, const QBrush &bright_text, const QBrush &base, const QBrush &window)
Sets a the group at cg.
Definition: qpalette.cpp:1246

◆ setColorGroup() [3/3]

void QPalette::setColorGroup ( ColorGroup  cg,
const QBrush foreground,
const QBrush button,
const QBrush light,
const QBrush dark,
const QBrush mid,
const QBrush text,
const QBrush bright_text,
const QBrush base,
const QBrush alternate_base,
const QBrush background,
const QBrush midlight,
const QBrush button_text,
const QBrush shadow,
const QBrush highlight,
const QBrush highlighted_text,
const QBrush link,
const QBrush link_visited,
const QBrush toolTipBase,
const QBrush toolTipText 
)
private
Warning
This function is not part of the public interface.

Definition at line 1287 of file qpalette.cpp.

1296 {
1297  detach();
1298  setBrush(cg, WindowText, foreground);
1299  setBrush(cg, Button, button);
1300  setBrush(cg, Light, light);
1301  setBrush(cg, Dark, dark);
1302  setBrush(cg, Mid, mid);
1303  setBrush(cg, Text, text);
1304  setBrush(cg, BrightText, bright_text);
1305  setBrush(cg, Base, base);
1306  setBrush(cg, AlternateBase, alternate_base);
1307  setBrush(cg, Window, background);
1308  setBrush(cg, Midlight, midlight);
1309  setBrush(cg, ButtonText, button_text);
1310  setBrush(cg, Shadow, shadow);
1311  setBrush(cg, Highlight, highlight);
1312  setBrush(cg, HighlightedText, highlighted_text);
1313  setBrush(cg, Link, link);
1314  setBrush(cg, LinkVisited, link_visited);
1315  setBrush(cg, ToolTipBase, toolTipBase);
1316  setBrush(cg, ToolTipText, toolTipText);
1317 }
void detach()
Definition: qpalette.cpp:953
void setBrush(ColorRole cr, const QBrush &brush)
Sets the brush for the given color role to the specified brush for all groups in the palette...
Definition: qpalette.h:206
The Text item allows you to add formatted text to a scene.
Button
Definition: qmessagebox.cpp:82

◆ setCurrentColorGroup()

void QPalette::setCurrentColorGroup ( ColorGroup  cg)
inline

◆ shadow()

const QBrush & QPalette::shadow ( ) const
inline

◆ text()

const QBrush & QPalette::text ( ) const
inline

◆ toolTipBase()

const QBrush & QPalette::toolTipBase ( ) const
inline

Returns the tool tip base brush of the current color group.

Since
4.4

This brush is used by QToolTip and QWhatsThis.

Note
Tool tips use the Inactive color group of QPalette, because tool tips are not active windows.
See also
ColorRole brush()

Definition at line 132 of file qpalette.h.

Referenced by QCommonStyle::drawPrimitive(), and setColorGroup().

132 { return brush(ToolTipBase); }
const QBrush & brush(ColorGroup cg, ColorRole cr) const
Returns the brush in the specified color group, used for the given color role.
Definition: qpalette.cpp:874

◆ toolTipText()

const QBrush & QPalette::toolTipText ( ) const
inline

Returns the tool tip text brush of the current color group.

Since
4.4

This brush is used by QToolTip and QWhatsThis.

Note
Tool tips use the Inactive color group of QPalette, because tool tips are not active windows.
See also
ColorRole brush()

Definition at line 133 of file qpalette.h.

Referenced by QCommonStyle::drawPrimitive(), QWhatsThat::paintEvent(), and setColorGroup().

133 { return brush(ToolTipText); }
const QBrush & brush(ColorGroup cg, ColorRole cr) const
Returns the brush in the specified color group, used for the given color role.
Definition: qpalette.cpp:874

◆ window()

const QBrush & QPalette::window ( ) const
inline

Returns the window (general background) brush of the current color group.

See also
ColorRole brush()

Definition at line 135 of file qpalette.h.

Referenced by _q_paintItem(), QPlastiqueStyle::drawControl(), QPlastiqueStyle::drawPrimitive(), QGtkStyle::drawPrimitive(), QWindowsMobileStylePrivate::drawTabBarTab(), make_widget_eventUPP(), QDecorationStyled::paint(), and QPalette().

135 { return brush(Window); }
const QBrush & brush(ColorGroup cg, ColorRole cr) const
Returns the brush in the specified color group, used for the given color role.
Definition: qpalette.cpp:874

◆ windowText()

const QBrush & QPalette::windowText ( ) const
inline

Returns the window text (general foreground) brush of the current color group.

See also
ColorRole brush()

Definition at line 124 of file qpalette.h.

Referenced by QPlastiqueStyle::drawControl(), QMacStyle::drawControl(), and qt_graphicsItem_highlightSelected().

124 { return brush(WindowText); }
const QBrush & brush(ColorGroup cg, ColorRole cr) const
Returns the brush in the specified color group, used for the given color role.
Definition: qpalette.cpp:874

Friends and Related Functions

◆ operator<<

QDataStream & operator<< ( QDataStream s,
const QPalette p 
)
friend

Writes the palette, p to the stream s and returns a reference to the stream.

See also
Format of the QDataStream operators

Definition at line 1154 of file qpalette.cpp.

Referenced by setBrush().

1155 {
1156  for (int grp = 0; grp < (int)QPalette::NColorGroups; grp++) {
1157  if (s.version() == 1) {
1158  // Qt 1.x
1159  for (int i = 0; i < NumOldRoles; ++i)
1160  s << p.d->br[grp][oldRoles[i]].color();
1161  } else {
1162  int max = QPalette::ToolTipText + 1;
1163  if (s.version() <= QDataStream::Qt_2_1)
1164  max = QPalette::HighlightedText + 1;
1165  else if (s.version() <= QDataStream::Qt_4_3)
1166  max = QPalette::AlternateBase + 1;
1167  for (int r = 0; r < max; r++)
1168  s << p.d->br[grp][r];
1169  }
1170  }
1171  return s;
1172 }
const QColor & color() const
Returns the brush color.
Definition: qbrush.h:183
static const int NumOldRoles
Definition: qpalette.cpp:1138
QPalettePrivate * d
Definition: qpalette.h:195
QBrush br[QPalette::NColorGroups][QPalette::NColorRoles]
Definition: qpalette.cpp:55
int version() const
Returns the version number of the data serialization format.
Definition: qdatastream.h:212
static const int oldRoles[7]
Definition: qpalette.cpp:1139

◆ operator>>()

QDataStream & operator>> ( QDataStream s,
QPalette p 
)
related

Reads a palette from the stream, s into the palette p, and returns a reference to the stream.

See also
Format of the QDataStream operators

Definition at line 1195 of file qpalette.cpp.

Referenced by setBrush().

1196 {
1197  if(s.version() == 1) {
1198  p = QPalette();
1202  } else {
1203  int max = QPalette::NColorRoles;
1204  if (s.version() <= QDataStream::Qt_2_1) {
1205  p = QPalette();
1206  max = QPalette::HighlightedText + 1;
1207  } else if (s.version() <= QDataStream::Qt_4_3) {
1208  p = QPalette();
1209  max = QPalette::AlternateBase + 1;
1210  }
1211 
1212  QBrush tmp;
1213  for(int grp = 0; grp < (int)QPalette::NColorGroups; ++grp) {
1214  for(int role = 0; role < max; ++role) {
1215  s >> tmp;
1217  }
1218  }
1219  }
1220  return s;
1221 }
ColorRole
The ColorRole enum defines the different symbolic color roles used in current GUIs.
Definition: qpalette.h:93
ColorGroup
Definition: qpalette.h:92
void setBrush(ColorRole cr, const QBrush &brush)
Sets the brush for the given color role to the specified brush for all groups in the palette...
Definition: qpalette.h:206
static void readV1ColorGroup(QDataStream &s, QPalette &pal, QPalette::ColorGroup grp)
Definition: qpalette.cpp:1174
int version() const
Returns the version number of the data serialization format.
Definition: qdatastream.h:212
The QBrush class defines the fill pattern of shapes drawn by QPainter.
Definition: qbrush.h:76
QPalette()
Constructs a palette object that uses the application&#39;s default palette.
Definition: qpalette.cpp:673

Properties

◆ current_group

uint QPalette::current_group
private

Definition at line 196 of file qpalette.h.

Referenced by brush(), init(), isEqual(), operator=(), operator==(), QPalette(), and setBrush().

◆ d

QPalettePrivate* QPalette::d
private

◆ resolve_mask

uint QPalette::resolve_mask
private

Definition at line 197 of file qpalette.h.

Referenced by init(), isBrushSet(), operator=(), QPalette(), resolve(), setBrush(), and setColorGroup().


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