QPalette Class▲
-
Header: QPalette
-
CMake:
find_package(Qt6 REQUIRED COMPONENTS Gui)
target_link_libraries(mytarget PRIVATE Qt6::Gui)
-
qmake: QT += gui
-
Group: QPalette is part of appearance, shared
Detailed Description▲
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:
-
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.
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 https://() and https://(). 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 https:// documentation.
We strongly recommend that you use the default palette of the current style (returned by https://()) 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 https://() and https://(), depending on whether you want a pure color or a pixmap pattern.
There are also corresponding https://() and https://() getters, and a commonly used convenience function to get the https:// for the current https://: https://(), https://(), https://(), etc.
You can copy a palette using the copy constructor and test to see if two palettes are identical using https://().
https:// is optimized by the use of https://, so it is very efficient to pass https:// objects as arguments.
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▲
See also QApplication::setPalette(), QWidget::setPalette(), https://
Member Type Documentation▲
enum QPalette::ColorGroup▲
|
Constant |
Value |
|
|---|---|---|
|
https://::Disabled |
1 |
|
|
https://::Active |
0 |
|
|
https://::Inactive |
2 |
|
|
https://::Normal |
Active |
synonym for Active |
enum QPalette::ColorRole▲
The ColorRole enum defines the different symbolic color roles used in current GUIs.
The central roles are:
|
Constant |
Value |
Description |
|---|---|---|
|
https://::Window |
10 |
A general background color. |
|
https://::WindowText |
0 |
A general foreground color. |
|
https://::Base |
9 |
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. |
|
https://::AlternateBase |
16 |
Used as the alternate background color in views with alternating row colors (see QAbstractItemView::setAlternatingRowColors()). |
|
https://::ToolTipBase |
18 |
Used as the background color for QToolTip and QWhatsThis. Tool tips use the Inactive color group of https://, because tool tips are not active windows. |
|
https://::ToolTipText |
19 |
Used as the foreground color for QToolTip and QWhatsThis. Tool tips use the Inactive color group of https://, because tool tips are not active windows. |
|
https://::PlaceholderText |
20 |
Used as the placeholder color for various text input widgets. This enum value has been introduced in Qt 5.12 |
|
https://::Text |
6 |
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. |
|
https://::Button |
1 |
The general button background color. This background can be different from Window as some styles require a different background color for buttons. |
|
https://::ButtonText |
8 |
A foreground color used with the Button color. |
|
https://::BrightText |
7 |
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.
|
Constant |
Value |
Description |
|---|---|---|
|
https://::Light |
2 |
Lighter than Button color. |
|
https://::Midlight |
3 |
Between Button and Light. |
|
https://::Dark |
4 |
Darker than Button. |
|
https://::Mid |
5 |
Between Button and Dark. |
|
https://::Shadow |
11 |
A very dark color. By default, the shadow color is https://. |
Selected (marked) items have two roles:
|
Constant |
Value |
Description |
|---|---|---|
|
https://::Highlight |
12 |
A color to indicate a selected item or the current item. By default, the highlight color is https://. |
|
https://::HighlightedText |
13 |
A text color that contrasts with Highlight. By default, the highlighted text color is https://. |
There are two color roles related to hyperlinks:
|
Constant |
Value |
Description |
|---|---|---|
|
https://::Link |
14 |
A text color used for unvisited hyperlinks. By default, the link color is https://. |
|
https://::LinkVisited |
15 |
A text color used for already visited hyperlinks. By default, the linkvisited color is https://. |
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 https://() 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);|
Constant |
Value |
Description |
|---|---|---|
|
https://::NoRole |
17 |
No role; this special role is often used to indicate that a role has not been assigned. |
Member Function Documentation▲
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▲
See also QApplication::setPalette(), QApplication::palette()
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.
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.
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.
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▲
See also https://
QPalette::QPalette(const QPalette &p)▲
Constructs a copy of p.
This constructor is fast thanks to https://.
[since 5.4] QPalette::QPalette(QPalette &&other)▲
Move-constructs a https:// 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.
This function was introduced in Qt 5.4.
QPalette::~QPalette()▲
Destroys the palette.
const QBrush &QPalette::alternateBase() const▲
Returns the alternate base brush of the current color group.
See Also▲
See also https://, https://()
const QBrush &QPalette::base() const▲
const QBrush &QPalette::brightText() const▲
Returns the bright text foreground brush of the current color group.
See Also▲
See also https://, https://()
const QBrush &QPalette::brush(QPalette::ColorGroup group, QPalette::ColorRole role) const▲
Returns the brush in the specified color group, used for the given color role.
See Also▲
See also https://(), https://(), https://
const QBrush &QPalette::brush(QPalette::ColorRole role) const▲
This is an overloaded function.
Returns the brush that has been set for the given color role in the current https://.
See Also▲
See also https://(), https://(), https://
const QBrush &QPalette::button() const▲
See Also▲
See also https://, https://()
const QBrush &QPalette::buttonText() const▲
See Also▲
See also https://, https://()
qint64 QPalette::cacheKey() const▲
Returns a number that identifies the contents of this https:// object. Distinct https:// objects can have the same key if they refer to the same contents.
The cacheKey() will change when the palette is altered.
const QColor &QPalette::color(QPalette::ColorGroup group, QPalette::ColorRole role) const▲
Returns the color in the specified color group, used for the given color role.
See Also▲
See also https://(), https://(), https://
const QColor &QPalette::color(QPalette::ColorRole role) const▲
This is an overloaded function.
Returns the color that has been set for the given color role in the current https://.
See Also▲
See also https://(), https://
QPalette::ColorGroup QPalette::currentColorGroup() const▲
const QBrush &QPalette::dark() const▲
const QBrush &QPalette::highlight() const▲
const QBrush &QPalette::highlightedText() const▲
Returns the highlighted text brush of the current color group.
See Also▲
See also https://, https://()
bool QPalette::isBrushSet(QPalette::ColorGroup cg, QPalette::ColorRole cr) const▲
Returns true if the https:// cg and https:// cr has been set previously on this palette; otherwise returns false.
The https:// cg should be less than https://, but you can use https://. In this case, the previously set current color group will be used.
The https:// cr should be less than https://.
See Also▲
See also https://(), https://()
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▲
See also https://(), https://()
bool QPalette::isEqual(QPalette::ColorGroup cg1, QPalette::ColorGroup cg2) const▲
Returns true (usually quickly) if color group cg1 is equal to cg2; otherwise returns false.
const QBrush &QPalette::light() const▲
const QBrush &QPalette::link() const▲
Returns the unvisited link text brush of the current color group.
See Also▲
See also https://, https://()
const QBrush &QPalette::linkVisited() const▲
Returns the visited link text brush of the current color group.
See Also▲
See also https://, https://()
const QBrush &QPalette::mid() const▲
const QBrush &QPalette::midlight() const▲
[since 5.12] const QBrush &QPalette::placeholderText() const▲
Returns the placeholder text brush of the current color group.
Before Qt 5.12, the placeholder text color was hard-coded as https://().https://() with an alpha of 128 applied. In Qt 6, it is an independent color.
This function was introduced in Qt 5.12.
See Also▲
See also https://, https://()
QPalette QPalette::resolve(const QPalette &other) const▲
Returns a new https:// that is a union of this instance and other. Color roles set in this instance take precedence.
void QPalette::setBrush(QPalette::ColorRole role, const QBrush &brush)▲
Sets the brush for the given color role to the specified brush for all groups in the palette.
See Also▲
See also https://(), https://(), https://
void QPalette::setBrush(QPalette::ColorGroup group, QPalette::ColorRole role, const QBrush &brush)▲
This is an overloaded function.
Sets the brush in the specified color group, used for the given color role, to brush.
See Also▲
See also https://(), https://(), https://
void QPalette::setColor(QPalette::ColorGroup group, QPalette::ColorRole role, const QColor &color)▲
Sets the color in the specified color group, used for the given color role, to the specified solid color.
See Also▲
See also https://(), https://(), https://
void QPalette::setColor(QPalette::ColorRole role, const QColor &color)▲
This is an overloaded function.
Sets the color used for the given color role, in all color groups, to the specified solid color.
See Also▲
See also https://(), https://(), https://
void QPalette::setColorGroup(QPalette::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▲
See also https://
void QPalette::setCurrentColorGroup(QPalette::ColorGroup cg)▲
const QBrush &QPalette::shadow() const▲
[since 5.0] void QPalette::swap(QPalette &other)▲
Swaps this palette instance with other. This function is very fast and never fails.
This function was introduced in Qt 5.0.
const QBrush &QPalette::text() const▲
Returns the text foreground brush of the current color group.
See Also▲
See also https://, https://()
const QBrush &QPalette::toolTipBase() const▲
Returns the tool tip base brush of the current color group. This brush is used by QToolTip and QWhatsThis.
Tool tips use the Inactive color group of https://, because tool tips are not active windows.
See Also▲
See also https://, https://()
const QBrush &QPalette::toolTipText() const▲
Returns the tool tip text brush of the current color group. This brush is used by QToolTip and QWhatsThis.
Tool tips use the Inactive color group of https://, because tool tips are not active windows.
See Also▲
See also https://, https://()
const QBrush &QPalette::window() const▲
Returns the window (general background) brush of the current color group.
See Also▲
See also https://, https://()
const QBrush &QPalette::windowText() const▲
Returns the window text (general foreground) brush of the current color group.
See Also▲
See also https://, https://()
QVariant QPalette::operator QVariant() const▲
Returns the palette as a https://
bool QPalette::operator!=(const QPalette &p) const▲
Returns true (slowly) if this palette is different from p; otherwise returns false (usually quickly).
The current https:// is not taken into account when comparing palettes
See Also▲
See also https://()
QPalette &QPalette::operator=(const QPalette &p)▲
Assigns p to this palette and returns a reference to this palette.
This operation is fast thanks to https://.
[since 5.2] QPalette &QPalette::operator=(QPalette &&other)▲
Move-assigns other to this https:// instance.
This function was introduced in Qt 5.2.
bool QPalette::operator==(const QPalette &p) const▲
Returns true (usually quickly) if this palette is equal to p; otherwise returns false (slowly).
The current https:// is not taken into account when comparing palettes
See Also▲
See also https://()
Related Non-Members▲
QDataStream &operator<<(QDataStream &s, const QPalette &p)▲
Writes the palette, p to the stream s and returns a reference to the stream.
See Also▲
See also https://
QDataStream &operator>>(QDataStream &s, QPalette &p)▲
Reads a palette from the stream, s into the palette p, and returns a reference to the stream.
See Also▲
See also https://
Obsolete Members for QPalette▲
The following members of class https:// are deprecated. We strongly advise against using them in new code.
Obsolete Member Function Documentation▲
QPalette::QPalette(const QColor &windowText, const QColor &window, const QColor &light, const QColor &dark, const QColor &mid, const QColor &text, const QColor &base)▲
This function is deprecated. We strongly advise against using it in new code.
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.



