Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
QPalette Class Reference

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

#include <qpalette.h>

+ Collaboration diagram for QPalette:

Public Types

enum  ColorGroup {
  Active , Disabled , Inactive , NColorGroups ,
  Current , All , Normal = Active
}
 \value Disabled \value Active \value Inactive \value Normal synonym for Active More...
 
enum  ColorRole {
  WindowText , Button , Light , Midlight ,
  Dark , Mid , Text , BrightText ,
  ButtonText , Base , Window , Shadow ,
  Highlight , HighlightedText , Link , LinkVisited ,
  AlternateBase , NoRole , ToolTipBase , ToolTipText ,
  PlaceholderText , Accent , NColorRoles = Accent + 1
}
 
using ResolveMask = quint64
 

Public Member Functions

 QPalette ()
 Constructs an empty palette object with no color roles set.
 
 QPalette (const QColor &button)
 Constructs a palette from the button color.
 
 QPalette (Qt::GlobalColor button)
 Constructs a palette from the button color.
 
 QPalette (const QColor &button, const QColor &window)
 Constructs a palette from a button color and a window.
 
 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.
 
 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.
 
 ~QPalette ()
 Destroys the palette.
 
QPaletteoperator= (const QPalette &palette)
 Move-assigns other to this QPalette instance.
 
 QPalette (QPalette &&other) noexcept
 
void swap (QPalette &other) noexcept
 
 operator QVariant () const
 Returns the palette as a QVariant.
 
ColorGroup currentColorGroup () const
 Returns the palette's current color group.
 
void setCurrentColorGroup (ColorGroup cg)
 Set the palette's current color group to cg.
 
const QColorcolor (ColorGroup cg, ColorRole cr) const
 Returns the color in the specified color group, used for the given color role.
 
const QBrushbrush (ColorGroup cg, ColorRole cr) const
 Returns the brush in the specified color group, used for the given color role.
 
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.
 
void setColor (ColorRole cr, const QColor &color)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets the color used for the given color role, in all color groups, to the specified solid color.
 
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.
 
bool isBrushSet (ColorGroup cg, ColorRole cr) const
 
void setBrush (ColorGroup cg, ColorRole cr, const QBrush &brush)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets the brush in the specified color group, used for the given color role, to brush.
 
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.
 
bool isEqual (ColorGroup cr1, ColorGroup cr2) const
 Returns true (usually quickly) if color group cg1 is equal to cg2; otherwise returns false.
 
const QColorcolor (ColorRole cr) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns the color that has been set for the given color role in the current ColorGroup.
 
const QBrushbrush (ColorRole cr) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns the brush that has been set for the given color role in the current ColorGroup.
 
const QBrushwindowText () const
 Returns the window text (general foreground) brush of the current color group.
 
const QBrushbutton () const
 Returns the button brush of the current color group.
 
const QBrushlight () const
 Returns the light brush of the current color group.
 
const QBrushdark () const
 Returns the dark brush of the current color group.
 
const QBrushmid () const
 Returns the mid brush of the current color group.
 
const QBrushtext () const
 Returns the text foreground brush of the current color group.
 
const QBrushbase () const
 Returns the base brush of the current color group.
 
const QBrushalternateBase () const
 Returns the alternate base brush of the current color group.
 
const QBrushtoolTipBase () const
 
const QBrushtoolTipText () const
 
const QBrushwindow () const
 Returns the window (general background) brush of the current color group.
 
const QBrushmidlight () const
 Returns the midlight brush of the current color group.
 
const QBrushbrightText () const
 Returns the bright text foreground brush of the current color group.
 
const QBrushbuttonText () const
 Returns the button text foreground brush of the current color group.
 
const QBrushshadow () const
 Returns the shadow brush of the current color group.
 
const QBrushhighlight () const
 Returns the highlight brush of the current color group.
 
const QBrushhighlightedText () const
 Returns the highlighted text brush of the current color group.
 
const QBrushlink () const
 Returns the unvisited link text brush of the current color group.
 
const QBrushlinkVisited () const
 Returns the visited link text brush of the current color group.
 
const QBrushplaceholderText () const
 
const QBrushaccent () const
 
bool operator== (const QPalette &p) const
 Returns true (usually quickly) if this palette is equal to p; otherwise returns false (slowly).
 
bool operator!= (const QPalette &p) const
 Returns true (slowly) if this palette is different from p; otherwise returns false (usually quickly).
 
bool isCopyOf (const QPalette &p) const
 Returns true if this palette and p are copies of each other, i.e.
 
qint64 cacheKey () const
 Returns a number that identifies the contents of this QPalette object.
 
QPalette resolve (const QPalette &other) const
 Returns a new QPalette that is a union of this instance and other.
 
ResolveMask resolveMask () const
 
void setResolveMask (ResolveMask mask)
 

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.
 

Related Symbols

(Note that these are not member symbols.)

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

Detailed Description

The QPalette class contains color groups for each widget state.

\inmodule QtGui

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: \list

  • The Active group is used for the window that has keyboard focus.
  • The Inactive group is used for other windows.
  • The Disabled group is used for widgets (not windows) that are disabled for some reason. \endlist

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 \l ColorRole documentation.

We strongly recommend that you use the default palette of the current style (returned by QGuiApplication::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 \l{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 Vista and the \macos styles.
See also
QApplication::setPalette(), QWidget::setPalette(), QColor

Definition at line 18 of file qpalette.h.

Member Typedef Documentation

◆ ResolveMask

Definition at line 113 of file qpalette.h.

Member Enumeration Documentation

◆ ColorGroup

\value Disabled \value Active \value Inactive \value Normal synonym for Active

\omitvalue All \omitvalue NColorGroups \omitvalue Current

Enumerator
Active 
Disabled 
Inactive 
NColorGroups 
Current 
All 
Normal 

Definition at line 49 of file qpalette.h.

◆ ColorRole

Color Roles

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

The central roles are:

\value Window A general background color.

\value WindowText A general foreground color.

\value 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.

\value AlternateBase Used as the alternate background color in views with alternating row colors (see QAbstractItemView::setAlternatingRowColors()).

\value 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.

\value 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.

\value PlaceholderText Used as the placeholder color for various text input widgets. This enum value has been introduced in Qt 5.12

\value 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.

\value Button The general button background color. This background can be different from Window as some styles require a different background color for buttons.

\value ButtonText A foreground color used with the Button color.

\value 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.

\value Light Lighter than Button color.

\value Midlight Between Button and Light.

\value Dark Darker than Button.

\value Mid Between Button and Dark.

\value Shadow A very dark color. By default, the shadow color is Qt::black.

Selected (marked) items have two roles:

\value Highlight A color to indicate a selected item or the current item. By default, the highlight color is Qt::darkBlue.

\value [since 6.6] Accent A color that typically contrasts or complements Base, Window and Button colors. It usually represents the users' choice of desktop personalisation. Styling of interactive components is a typical use case. Unless explicitly set, it defaults to Highlight.

\value 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:

\value Link A text color used for unvisited hyperlinks. By default, the link color is Qt::blue.

\value 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);

\value NoRole No role; this special role is often used to indicate that a role has not been assigned.

\omitvalue NColorRoles

Enumerator
WindowText 
Button 
Light 
Midlight 
Dark 
Mid 
Text 
BrightText 
ButtonText 
Base 
Window 
Shadow 
Highlight 
HighlightedText 
Link 
LinkVisited 
AlternateBase 
NoRole 
ToolTipBase 
ToolTipText 
PlaceholderText 
Accent 
NColorRoles 

Definition at line 51 of file qpalette.h.

Constructor & Destructor Documentation

◆ QPalette() [1/8]

QPalette::QPalette ( )

Constructs an empty palette object with no color roles set.

When used as the palette of a QWidget the colors are resolved as described by QWidget::setPalette().

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

Definition at line 544 of file qpalette.cpp.

References QGuiApplicationPrivate::app_pal, Qt::black, qt_palette_from_color(), QBasicAtomicInteger< T >::ref(), QPalettePrivate::ref, QPalettePrivate::resolveMask, and setResolveMask().

+ Here is the call graph for this function:

◆ QPalette() [2/8]

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 566 of file qpalette.cpp.

References button(), and qt_palette_from_color().

+ Here is the call graph for this function:

◆ QPalette() [3/8]

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 577 of file qpalette.cpp.

References button(), and qt_palette_from_color().

+ Here is the call graph for this function:

◆ QPalette() [4/8]

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 629 of file qpalette.cpp.

References Active, Qt::black, button(), Qt::darkGray, Disabled, Inactive, qt_ensure_default_accent_color(), qt_placeholder_from_text(), setColorGroup(), Qt::white, and window().

+ Here is the call graph for this function:

◆ QPalette() [5/8]

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 590 of file qpalette.cpp.

References All, base(), button(), dark(), light(), mid(), qt_ensure_default_accent_color(), qt_placeholder_from_text(), setColorGroup(), text(), window(), and windowText().

+ Here is the call graph for this function:

◆ QPalette() [6/8]

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

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 612 of file qpalette.cpp.

References All, base(), dark(), light(), mid(), setColorGroup(), text(), window(), and windowText().

+ Here is the call graph for this function:

◆ QPalette() [7/8]

QPalette::QPalette ( const QPalette & p)

Constructs a copy of p.

This constructor is fast thanks to \l{implicit sharing}.

Definition at line 667 of file qpalette.cpp.

References QBasicAtomicInteger< T >::ref(), and QPalettePrivate::ref.

+ Here is the call graph for this function:

◆ ~QPalette()

QPalette::~QPalette ( )

Destroys the palette.

Definition at line 687 of file qpalette.cpp.

References QBasicAtomicInteger< T >::deref(), and QPalettePrivate::ref.

+ Here is the call graph for this function:

◆ QPalette() [8/8]

QPalette::QPalette ( QPalette && other)
inlinenoexcept
Since
5.4

Move-constructs a QPalette instance, making it point at the same object that other was pointing to.

After being moved from, you can only assign to or destroy other. Any other operation will result in undefined behavior.

Definition at line 34 of file qpalette.h.

Member Function Documentation

◆ accent()

const QBrush & QPalette::accent ( ) const
inline
Since
6.6

Returns the accent brush of the current color group.

See also
ColorRole, brush()

Definition at line 103 of file qpalette.h.

◆ alternateBase()

const QBrush & QPalette::alternateBase ( ) const
inline

Returns the alternate base brush of the current color group.

See also
ColorRole, brush()

Definition at line 90 of file qpalette.h.

◆ base()

const QBrush & QPalette::base ( ) const
inline

Returns the base brush of the current color group.

See also
ColorRole, brush()

Definition at line 89 of file qpalette.h.

Referenced by QPalette(), QPalette(), QQC2::QCommonStyle::drawControl(), QCommonStyle::drawControl(), QWindows11Style::drawPrimitive(), QQC2::QWindowsStyle::drawPrimitive(), QMacStyle::drawPrimitive(), QWizardHeader::paintEvent(), QWindowsVistaStyle::polish(), qt_ensure_default_accent_color(), and setColorGroup().

+ Here is the caller graph for this function:

◆ 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 95 of file qpalette.h.

◆ brush() [1/2]

◆ brush() [2/2]

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

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns the brush that has been set for the given color role in the current ColorGroup.

See also
color(), setBrush(), ColorRole

Definition at line 82 of file qpalette.h.

References brush().

Referenced by brush().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ button()

const QBrush & QPalette::button ( ) const
inline

Returns the button brush of the current color group.

See also
ColorRole, brush()

Definition at line 84 of file qpalette.h.

Referenced by QPalette(), QPalette(), QPalette(), QPalette(), QQC2_NAMESPACE::QMacStyle::drawComplexControl(), QQC2::QCommonStyle::drawComplexControl(), QQC2::QWindowsStyle::drawComplexControl(), QMacStyle::drawComplexControl(), QCommonStyle::drawComplexControl(), QQC2::QWindowsStyle::drawControl(), QQC2::QStyleHelper::drawDial(), QQC2::QWindowsStyle::drawPrimitive(), qDrawWinButton(), QQC2::qDrawWinButton(), setColorGroup(), and toolTipPalette().

+ Here is the caller graph for this function:

◆ 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 96 of file qpalette.h.

Referenced by QQC2_NAMESPACE::QMacStyle::drawControl(), QMacStyle::drawControl(), QWindows11Style::drawControl(), QWindows11Style::drawPrimitive(), QQC2::QCommonStyle::drawPrimitive(), QCommonStyle::drawPrimitive(), QCommandLinkButton::paintEvent(), and toolTipPalette().

+ Here is the caller graph for this function:

◆ 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 943 of file qpalette.cpp.

References QPalettePrivate::data, and QPalettePrivate::detach_no.

◆ color() [1/2]

◆ color() [2/2]

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

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Returns the color that has been set for the given color role in the current ColorGroup.

See also
brush(), ColorRole

Definition at line 81 of file qpalette.h.

References color().

Referenced by color().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ currentColorGroup()

ColorGroup QPalette::currentColorGroup ( ) const
inline

Returns the palette's current color group.

Definition at line 64 of file qpalette.h.

Referenced by QLineEdit::paintEvent(), QQuickPaletteColorProvider::resetColor(), and QQuickPaletteColorProvider::resetColor().

+ Here is the caller graph for this function:

◆ dark()

◆ highlight()

const QBrush & QPalette::highlight ( ) const
inline

Returns the highlight brush of the current color group.

See also
ColorRole, brush()

Definition at line 98 of file qpalette.h.

Referenced by QQC2::QStyleHelper::drawDial().

+ Here is the caller graph for this function:

◆ highlightedText()

const QBrush & QPalette::highlightedText ( ) const
inline

Returns the highlighted text brush of the current color group.

See also
ColorRole, brush()

Definition at line 99 of file qpalette.h.

Referenced by QQC2_NAMESPACE::QMacStyle::drawPrimitive(), QQC2::QCommonStyle::drawPrimitive(), QQC2::QWindowsStyle::drawPrimitive(), QMacStyle::drawPrimitive(), and QCommonStyle::drawPrimitive().

+ Here is the caller graph for this function:

◆ isBrushSet()

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

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

The ColorGroup cg should be less than QPalette::NColorGroups, but you can use QPalette::Current. In this case, the previously set current color group will be used.

The ColorRole cr should be less than QPalette::NColorRoles.

See also
setBrush(), currentColorGroup()

Definition at line 825 of file qpalette.cpp.

References QPalettePrivate::bitPosition(), Current, NColorGroups, NColorRoles, NoRole, qWarning, and QPalettePrivate::resolveMask.

Referenced by qt_ensure_default_accent_color(), and qt_placeholder_from_text().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ 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 1137 of file qpalette.cpp.

Referenced by operator==().

+ Here is the caller graph for this function:

◆ 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 909 of file qpalette.cpp.

References Active, Current, QPalettePrivate::data, NColorGroups, NColorRoles, and qWarning.

◆ light()

◆ 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 100 of file qpalette.h.

Referenced by QTextMarkdownImporter::cbEnterSpan().

+ Here is the caller graph for this function:

◆ 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 101 of file qpalette.h.

◆ mid()

const QBrush & QPalette::mid ( ) const
inline

Returns the mid brush of the current color group.

See also
ColorRole, brush()

Definition at line 87 of file qpalette.h.

Referenced by QPalette(), QPalette(), QQC2::QCommonStyle::drawPrimitive(), QCommonStyle::drawPrimitive(), QWizardHeader::paintEvent(), qDrawShadeLine(), QQC2::qDrawShadeLine(), qDrawShadeRect(), QQC2::qDrawShadeRect(), and setColorGroup().

+ Here is the caller graph for this function:

◆ midlight()

const QBrush & QPalette::midlight ( ) const
inline

Returns the midlight brush of the current color group.

See also
ColorRole, brush()

Definition at line 94 of file qpalette.h.

Referenced by QQC2::QWindowsStyle::drawPrimitive(), qDrawShadePanel(), QQC2::qDrawShadePanel(), qDrawWinPanel(), and QQC2::qDrawWinPanel().

+ Here is the caller graph for this function:

◆ operator QVariant()

QPalette::operator QVariant ( ) const

Returns the palette as a QVariant.

Definition at line 726 of file qpalette.cpp.

References QVariant::fromValue().

+ Here is the call graph for this function:

◆ 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 106 of file qpalette.h.

References operator==().

+ Here is the call graph for this function:

◆ operator=()

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

Move-assigns other to this QPalette instance.

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

Since
5.2

This operation is fast thanks to \l{implicit sharing}.

Definition at line 705 of file qpalette.cpp.

References QBasicAtomicInteger< T >::deref(), QBasicAtomicInteger< T >::ref(), and QPalettePrivate::ref.

+ Here is the call graph for this function:

◆ 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 following is not taken into account when comparing palettes: \list
  • the current ColorGroup
  • ColorRole NoRole
Since
6.6 \endlist
See also
operator!=()

Definition at line 887 of file qpalette.cpp.

References QPalettePrivate::data, isCopyOf(), NColorGroups, NColorRoles, and NoRole.

+ Here is the call graph for this function:

◆ placeholderText()

const QBrush & QPalette::placeholderText ( ) const
inline
Since
5.12

Returns the placeholder text brush of the current color group.

Note
Before Qt 5.12, the placeholder text color was hard-coded as QPalette::text().color() with an alpha of 128 applied. In Qt 6, it is an independent color.
See also
ColorRole, brush()

Definition at line 102 of file qpalette.h.

Referenced by QTextEditPrivate::paint(), QLineEdit::paintEvent(), and QComboBox::paintEvent().

+ Here is the caller graph for this function:

◆ resolve()

QPalette QPalette::resolve ( const QPalette & other) const

Returns a new QPalette that is a union of this instance and other.

Color roles set in this instance take precedence.

Definition at line 963 of file qpalette.cpp.

References allResolveMask(), QPalettePrivate::bitPosition(), NColorGroups, NColorRoles, NoRole, o, other(), palette, and QPalettePrivate::resolveMask.

Referenced by QQuickTheme::palette(), QGraphicsScenePrivate::resolvePalette(), QWidgetPrivate::resolvePalette(), QGraphicsWidgetPrivate::resolvePalette(), QWidget::setPalette(), QGuiApplicationPrivate::setPalette(), QGraphicsScene::setPalette(), and QGraphicsWidget::setPalette().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ resolveMask()

◆ setBrush() [1/2]

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

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets the brush in the specified color group, used for the given color role, to brush.

See also
brush(), setColor(), ColorRole

Definition at line 780 of file qpalette.cpp.

References Active, All, QPalettePrivate::bitPosition(), Current, QPalettePrivate::data, QExplicitlySharedDataPointer< T >::detach(), i, NColorGroups, NColorRoles, Q_ASSERT, qWarning, QPalettePrivate::resolveMask, and setBrush().

+ Here is the call graph for this function:

◆ setBrush() [2/2]

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

Sets the brush for the given color role to the specified brush for all groups in the palette.

See also
brush(), setColor(), ColorRole

Definition at line 151 of file qpalette.h.

References All, and setBrush().

Referenced by QQuickPaletteColorProvider::copyColorGroup(), QQC2::QCommonStyle::drawComplexControl(), QCommonStyle::drawComplexControl(), QHeaderView::initStyleOptionForIndex(), QComboBox::paintEvent(), QWindowsVistaStyle::polish(), QPixmapStyle::polish(), qt_ensure_default_accent_color(), qt_mac_createRolePalettes(), QWizardPrivate::recreateLayout(), setBrush(), setBrush(), QItemDelegate::setOptions(), and QAndroidPlatformTheme::updateStyle().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setColor() [1/2]

◆ setColor() [2/2]

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

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Sets the color used for the given color role, in all color groups, to the specified solid color.

See also
brush(), setColor(), ColorRole

Definition at line 149 of file qpalette.h.

References All, and setColor().

+ Here is the call graph for this function:

◆ setColorGroup()

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 1150 of file qpalette.cpp.

References Active, All, base(), QPalettePrivate::bitPosition(), Qt::black, Qt::blue, button(), QBrush::color(), dark(), Qt::darkBlue, Highlight, light(), LinkVisited, Qt::magenta, mid(), NColorGroups, qt_mix_colors(), QPalettePrivate::resolveMask, setColorGroup(), text(), toolTipBase(), toolTipText(), Qt::white, window(), and windowText().

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

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setCurrentColorGroup()

void QPalette::setCurrentColorGroup ( ColorGroup cg)
inline

Set the palette's current color group to cg.

Definition at line 65 of file qpalette.h.

Referenced by QTableViewPrivate::drawCell(), QQC2::QCommonStyle::drawComplexControl(), QQC2::QWindowsStyle::drawComplexControl(), QCommonStyle::drawComplexControl(), QQC2_NAMESPACE::QMacStyle::drawControl(), QMacStyle::drawControl(), QTreeView::drawRow(), QWidget::palette(), and QMdiSubWindowPrivate::titleBarOptions().

+ Here is the caller graph for this function:

◆ setResolveMask()

void QPalette::setResolveMask ( QPalette::ResolveMask mask)

Definition at line 1007 of file qpalette.cpp.

References QPalettePrivate::resolveMask.

Referenced by QPalette(), QGraphicsWidgetPrivate::naturalWidgetPalette(), QWidgetPrivate::naturalWidgetPalette(), QQuickTheme::palette(), QWindowsVistaStyle::polish(), QQuickPaletteColorProvider::resetColor(), and QQuickPaletteColorProvider::resetColor().

+ Here is the caller graph for this function:

◆ shadow()

const QBrush & QPalette::shadow ( ) const
inline

Returns the shadow brush of the current color group.

See also
ColorRole, brush()

Definition at line 97 of file qpalette.h.

Referenced by QQC2::QWindowsStyle::drawControl(), QQC2::QWindowsStyle::drawPrimitive(), qDrawShadePanel(), QQC2::qDrawShadePanel(), qDrawWinButton(), QQC2::qDrawWinButton(), qDrawWinPanel(), and QQC2::qDrawWinPanel().

+ Here is the caller graph for this function:

◆ swap()

void QPalette::swap ( QPalette & other)
inlinenoexcept
Since
5.0

Swaps this palette instance with other. This function is very fast and never fails.

Definition at line 39 of file qpalette.h.

References d, other(), and qt_ptr_swap().

+ Here is the call graph for this function:

◆ text()

const QBrush & QPalette::text ( ) const
inline

◆ toolTipBase()

const QBrush & QPalette::toolTipBase ( ) const
inline
Since
4.4

Returns the tool tip base brush of the current color group. 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 91 of file qpalette.h.

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

+ Here is the caller graph for this function:

◆ toolTipText()

const QBrush & QPalette::toolTipText ( ) const
inline
Since
4.4

Returns the tool tip text brush of the current color group. 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 92 of file qpalette.h.

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

+ Here is the caller graph for this function:

◆ 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 93 of file qpalette.h.

Referenced by QPalette(), QPalette(), QPalette(), _q_paintItem(), QAndroidStyle::AndroidControl::drawControl(), QQC2_NAMESPACE::QMacStyle::drawControl(), QQC2::QCommonStyle::drawControl(), QQC2::QWindowsStyle::drawControl(), QMacStyle::drawControl(), QCommonStyle::drawControl(), QQC2_NAMESPACE::QMacStyle::drawPrimitive(), QQC2::QWindowsStyle::drawPrimitive(), QMacStyle::drawPrimitive(), QComboMenuDelegate::paint(), QWindows11Style::polish(), and setColorGroup().

+ Here is the caller graph for this function:

◆ 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 83 of file qpalette.h.

Referenced by QPalette(), QPalette(), QQC2::QCommonStyle::drawComplexControl(), QCommonStyle::drawComplexControl(), QAndroidStyle::AndroidControl::drawControl(), QQC2::QCommonStyle::drawControl(), QCommonStyle::drawControl(), QQC2::QCommonStyle::drawPrimitive(), QCommonStyle::drawPrimitive(), and setColorGroup().

+ Here is the caller graph for this function:

Friends And Related Symbol Documentation

◆ operator<<() [1/2]

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

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

See also
{Serializing Qt Data Types}{Format of the QDataStream operators}

Definition at line 1043 of file qpalette.cpp.

◆ operator<< [2/2]

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
{Serializing Qt Data Types}{Format of the QDataStream operators}

Definition at line 1043 of file qpalette.cpp.

◆ 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
{Serializing Qt Data Types}{Format of the QDataStream operators}

Definition at line 1086 of file qpalette.cpp.

References Accent, Active, AlternateBase, Disabled, Highlight, HighlightedText, Inactive, NColorGroups, NColorRoles, PlaceholderText, readV1ColorGroup(), and ToolTipText.

+ Here is the call graph for this function:

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