6.0.0-rc4Source

QPalette Class

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

Header#include <QPalette>
CMaketarget_link_libraries(app PRIVATE Nt::Gui)
ModuleNt GUI C++ Classes

List of all members, including inherited members

Public Types

Public Functions

QPalette()
QPalette(const QColor &button)
QPalette(const QColor &button, const QColor &window)
ColorGroupcurrentColorGroup() const
voidsetCurrentColorGroup(ColorGroup group)
const QBrush &brush(ColorGroup group, ColorRole role) const
const QBrush &brush(ColorRole role) const
voidsetBrush(ColorGroup group, ColorRole role, const QBrush &brush)
voidsetBrush(ColorRole role, const QBrush &brush)
const QColor &color(ColorGroup group, ColorRole role) const
const QColor &color(ColorRole role) const
voidsetColor(ColorGroup group, ColorRole role, const QColor &color)
voidsetColor(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.

See also QBrush and QColor.

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.

ConstantDescription
QPalette::ActiveThe window has the keyboard focus.
QPalette::DisabledThe widget is disabled.
QPalette::InactiveThe window does not have the keyboard focus.
QPalette::NColorGroupsThe number of groups.
QPalette::CurrentThe group that currentColorGroup() names.
QPalette::AllEvery group; setBrush() and setColor() accept it.
QPalette::NormalThe same as Active.

enum QPalette::ColorRole

This enum names the parts of the user interface that have a color.

ConstantDescription
QPalette::WindowTextThe general foreground color.
QPalette::ButtonThe background of buttons.
QPalette::LightLighter than Button; used for bevels.
QPalette::MidlightBetween Button and Light.
QPalette::DarkDarker than Button; used for bevels.
QPalette::MidBetween Button and Dark.
QPalette::TextThe foreground on Base, such as the text of a line edit.
QPalette::BrightTextA text color that contrasts with the dark colors.
QPalette::ButtonTextA foreground color for buttons.
QPalette::BaseThe background of text entry widgets.
QPalette::WindowThe general background color.
QPalette::ShadowA very dark color for shadows.
QPalette::HighlightThe background of selected items.
QPalette::HighlightedTextThe text on a Highlight.
QPalette::LinkThe color of hyperlinks.
QPalette::LinkVisitedThe color of visited hyperlinks.
QPalette::AlternateBaseThe alternate background in lists with alternating rows.
QPalette::NoRoleA role that is not a role.
QPalette::ToolTipBaseThe background of tool tips.
QPalette::ToolTipTextThe text color of tool tips.
QPalette::PlaceholderTextThe color of placeholder text.
QPalette::NColorRolesThe number of roles.
QPalette::ForegroundThe same as WindowText.
QPalette::BackgroundThe 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().

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().