QPalette Class
The QPalette class contains color groups for each widget state. More…
| Header | #include <QPalette> |
|---|---|
| CMake | target_link_libraries(app PRIVATE Nt::Gui) |
| Module | Nt GUI C++ Classes |
List of all members, including inherited members
Public Types
| enum | ColorGroup |
| enum | ColorRole |
Public Functions
| QPalette() | |
| QPalette(const QColor &button) | |
| QPalette(const QColor &button, const QColor &window) | |
| ColorGroup | currentColorGroup() const |
| void | setCurrentColorGroup(ColorGroup group) |
| const QBrush & | brush(ColorGroup group, ColorRole role) const |
| const QBrush & | brush(ColorRole role) const |
| void | setBrush(ColorGroup group, ColorRole role, const QBrush &brush) |
| void | setBrush(ColorRole role, const QBrush &brush) |
| const QColor & | color(ColorGroup group, ColorRole role) const |
| const QColor & | color(ColorRole role) const |
| void | setColor(ColorGroup group, ColorRole role, const QColor &color) |
| void | setColor(ColorRole role, const QColor &color) |
| const QBrush & | windowText() const |
| const QBrush & | button() const |
| const QBrush & | light() const |
| const QBrush & | midlight() const |
| const QBrush & | dark() const |
| const QBrush & | mid() const |
| const QBrush & | text() const |
| const QBrush & | brightText() const |
| const QBrush & | buttonText() const |
| const QBrush & | base() const |
| const QBrush & | window() const |
| const QBrush & | shadow() const |
| const QBrush & | highlight() const |
| const QBrush & | highlightedText() const |
| const QBrush & | link() const |
| const QBrush & | linkVisited() const |
| const QBrush & | alternateBase() const |
| const QBrush & | placeholderText() const |
Detailed Description
A palette maps color roles (the window background, text, buttons, selection) to brushes, separately for the active, disabled and inactive states of a widget. Widgets draw with the roles instead of fixed colors, so one palette changes the look of a whole application.
QPalette palette;
palette.setColor(QPalette::Window, QColor("#202020"));
palette.setColor(QPalette::WindowText, Qt::white);
widget->setPalette(palette);
The default palette is a light one. Text in the disabled group is gray.
Differences from Qt
The palette is a plain value: there is no resolve mask, cacheKey(), isBrushSet() or setColorGroup(), no QVariant or QDataStream conversion, and no constructors that take nine colors. The inactive group equals the active one until you change it.
Member Type Documentation
enum QPalette::ColorGroup
This enum names the states that a palette has colors for.
| Constant | Description |
|---|---|
QPalette::Active | The window has the keyboard focus. |
QPalette::Disabled | The widget is disabled. |
QPalette::Inactive | The window does not have the keyboard focus. |
QPalette::NColorGroups | The number of groups. |
QPalette::Current | The group that currentColorGroup() names. |
QPalette::All | Every group; setBrush() and setColor() accept it. |
QPalette::Normal | The same as Active. |
enum QPalette::ColorRole
This enum names the parts of the user interface that have a color.
| Constant | Description |
|---|---|
QPalette::WindowText | The general foreground color. |
QPalette::Button | The background of buttons. |
QPalette::Light | Lighter than Button; used for bevels. |
QPalette::Midlight | Between Button and Light. |
QPalette::Dark | Darker than Button; used for bevels. |
QPalette::Mid | Between Button and Dark. |
QPalette::Text | The foreground on Base, such as the text of a line edit. |
QPalette::BrightText | A text color that contrasts with the dark colors. |
QPalette::ButtonText | A foreground color for buttons. |
QPalette::Base | The background of text entry widgets. |
QPalette::Window | The general background color. |
QPalette::Shadow | A very dark color for shadows. |
QPalette::Highlight | The background of selected items. |
QPalette::HighlightedText | The text on a Highlight. |
QPalette::Link | The color of hyperlinks. |
QPalette::LinkVisited | The color of visited hyperlinks. |
QPalette::AlternateBase | The alternate background in lists with alternating rows. |
QPalette::NoRole | A role that is not a role. |
QPalette::ToolTipBase | The background of tool tips. |
QPalette::ToolTipText | The text color of tool tips. |
QPalette::PlaceholderText | The color of placeholder text. |
QPalette::NColorRoles | The number of roles. |
QPalette::Foreground | The same as WindowText. |
QPalette::Background | The same as Window. |
Member Function Documentation
QPalette::QPalette()
Constructs the default light palette.
QPalette::QPalette(const QColor &button)
Constructs a light palette whose Button color is button; the other colors of the roles that depend on it are made from it.
QPalette::QPalette(const QColor &button, const QColor &window)
This is an overloaded function.
Constructs a light palette whose Button color is button and whose Window color is window.
const QBrush & QPalette::alternateBase() const
Returns the AlternateBase brush of the current group.
See also brush().
const QBrush & QPalette::base() const
Returns the Base brush of the current group.
See also brush().
const QBrush & QPalette::brightText() const
Returns the BrightText brush of the current group.
See also brush().
const QBrush & QPalette::brush(ColorGroup group, ColorRole role) const
Returns the brush of role in group. group may be Current, which is the currentColorGroup().
See also setBrush().
const QBrush & QPalette::brush(ColorRole role) const
This is an overloaded function.
Returns the brush of role in the current group.
const QBrush & QPalette::button() const
Returns the Button brush of the current group.
See also brush().
const QBrush & QPalette::buttonText() const
Returns the ButtonText brush of the current group.
See also brush().
const QColor & QPalette::color(ColorGroup group, ColorRole role) const
Returns the color of role in group.
See also brush().
const QColor & QPalette::color(ColorRole role) const
This is an overloaded function.
Returns the color of role in the current group.
ColorGroup QPalette::currentColorGroup() const
Returns the group that the brush() and color() functions without a group use.
See also setCurrentColorGroup().
const QBrush & QPalette::dark() const
Returns the Dark brush of the current group.
See also brush().
const QBrush & QPalette::highlight() const
Returns the Highlight brush of the current group.
See also brush().
const QBrush & QPalette::highlightedText() const
Returns the HighlightedText brush of the current group.
See also brush().
const QBrush & QPalette::light() const
Returns the Light brush of the current group.
See also brush().
const QBrush & QPalette::link() const
Returns the Link brush of the current group.
See also brush().
const QBrush & QPalette::linkVisited() const
Returns the LinkVisited brush of the current group.
See also brush().
const QBrush & QPalette::mid() const
Returns the Mid brush of the current group.
See also brush().
const QBrush & QPalette::midlight() const
Returns the Midlight brush of the current group.
See also brush().
const QBrush & QPalette::placeholderText() const
Returns the PlaceholderText brush of the current group.
See also brush().
void QPalette::setBrush(ColorGroup group, ColorRole role, const QBrush &brush)
Sets the brush of role in group to brush. group may be All, which sets the role in every group, or Current.
See also brush().
void QPalette::setBrush(ColorRole role, const QBrush &brush)
This is an overloaded function.
Sets the brush of role in every group to brush.
void QPalette::setColor(ColorGroup group, ColorRole role, const QColor &color)
Sets the color of role in group to color.
See also setBrush().
void QPalette::setColor(ColorRole role, const QColor &color)
This is an overloaded function.
Sets the color of role in every group to color.
void QPalette::setCurrentColorGroup(ColorGroup group)
Sets the current group to group.
See also currentColorGroup().
const QBrush & QPalette::shadow() const
Returns the Shadow brush of the current group.
See also brush().
const QBrush & QPalette::text() const
Returns the Text brush of the current group.
See also brush().
const QBrush & QPalette::window() const
Returns the Window brush of the current group.
See also brush().
const QBrush & QPalette::windowText() const
Returns the WindowText brush of the current group.
See also brush().