#[repr(C)]pub struct QPalette { /* private fields */ }
Expand description
The QPalette class contains color groups for each widget state.
C++ class: QPalette
.
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:
- 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 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 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 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 macOS styles.
Implementations§
Source§impl QPalette
impl QPalette
Sourcepub unsafe fn alternate_base(&self) -> Ref<QBrush>
pub unsafe fn alternate_base(&self) -> Ref<QBrush>
Returns the alternate base brush of the current color group.
Calls C++ function: const QBrush& QPalette::alternateBase() const
.
Sourcepub unsafe fn background(&self) -> Ref<QBrush>
pub unsafe fn background(&self) -> Ref<QBrush>
Sourcepub unsafe fn base(&self) -> Ref<QBrush>
pub unsafe fn base(&self) -> Ref<QBrush>
Returns the base brush of the current color group.
Calls C++ function: const QBrush& QPalette::base() const
.
Sourcepub unsafe fn bright_text(&self) -> Ref<QBrush>
pub unsafe fn bright_text(&self) -> Ref<QBrush>
Returns the bright text foreground brush of the current color group.
Calls C++ function: const QBrush& QPalette::brightText() const
.
Sourcepub unsafe fn brush_2a(&self, cg: ColorGroup, cr: ColorRole) -> Ref<QBrush>
pub unsafe fn brush_2a(&self, cg: ColorGroup, cr: ColorRole) -> Ref<QBrush>
Returns the brush in the specified color group, used for the given color role.
Calls C++ function: const QBrush& QPalette::brush(QPalette::ColorGroup cg, QPalette::ColorRole cr) const
.
Sourcepub unsafe fn brush_1a(&self, cr: ColorRole) -> Ref<QBrush>
pub unsafe fn brush_1a(&self, cr: ColorRole) -> Ref<QBrush>
This is an overloaded function.
Calls C++ function: const QBrush& QPalette::brush(QPalette::ColorRole cr) const
.
This is an overloaded function.
Returns the brush that has been set for the given color role in the current ColorGroup.
Returns the button brush of the current color group.
Calls C++ function: const QBrush& QPalette::button() const
.
Returns the button text foreground brush of the current color group.
Calls C++ function: const QBrush& QPalette::buttonText() const
.
Sourcepub unsafe fn cache_key(&self) -> i64
pub unsafe fn cache_key(&self) -> i64
Sourcepub unsafe fn color_2a(&self, cg: ColorGroup, cr: ColorRole) -> Ref<QColor>
pub unsafe fn color_2a(&self, cg: ColorGroup, cr: ColorRole) -> Ref<QColor>
Returns the color in the specified color group, used for the given color role.
Calls C++ function: const QColor& QPalette::color(QPalette::ColorGroup cg, QPalette::ColorRole cr) const
.
Sourcepub unsafe fn color_1a(&self, cr: ColorRole) -> Ref<QColor>
pub unsafe fn color_1a(&self, cr: ColorRole) -> Ref<QColor>
This is an overloaded function.
Calls C++ function: const QColor& QPalette::color(QPalette::ColorRole cr) const
.
This is an overloaded function.
Returns the color that has been set for the given color role in the current ColorGroup.
Sourcepub unsafe fn copy_from(
&self,
palette: impl CastInto<Ref<QPalette>>,
) -> Ref<QPalette>
pub unsafe fn copy_from( &self, palette: impl CastInto<Ref<QPalette>>, ) -> Ref<QPalette>
Assigns p to this palette and returns a reference to this palette.
Calls C++ function: QPalette& QPalette::operator=(const QPalette& palette)
.
Assigns p to this palette and returns a reference to this palette.
This operation is fast thanks to implicit sharing.
Sourcepub unsafe fn current_color_group(&self) -> ColorGroup
pub unsafe fn current_color_group(&self) -> ColorGroup
Returns the palette's current color group.
Calls C++ function: QPalette::ColorGroup QPalette::currentColorGroup() const
.
Returns the palette’s current color group.
See also setCurrentColorGroup().
Sourcepub unsafe fn dark(&self) -> Ref<QBrush>
pub unsafe fn dark(&self) -> Ref<QBrush>
Returns the dark brush of the current color group.
Calls C++ function: const QBrush& QPalette::dark() const
.
Sourcepub unsafe fn foreground(&self) -> Ref<QBrush>
pub unsafe fn foreground(&self) -> Ref<QBrush>
Use windowText() instead.
Calls C++ function: const QBrush& QPalette::foreground() const
.
Use windowText() instead.
Sourcepub unsafe fn highlight(&self) -> Ref<QBrush>
pub unsafe fn highlight(&self) -> Ref<QBrush>
Returns the highlight brush of the current color group.
Calls C++ function: const QBrush& QPalette::highlight() const
.
Sourcepub unsafe fn highlighted_text(&self) -> Ref<QBrush>
pub unsafe fn highlighted_text(&self) -> Ref<QBrush>
Returns the highlighted text brush of the current color group.
Calls C++ function: const QBrush& QPalette::highlightedText() const
.
Sourcepub unsafe fn is_brush_set(&self, cg: ColorGroup, cr: ColorRole) -> bool
pub unsafe fn is_brush_set(&self, cg: ColorGroup, cr: ColorRole) -> bool
Returns true
if the ColorGroup cg and ColorRole cr has been set previously on this palette; otherwise returns false
.
Calls C++ function: bool QPalette::isBrushSet(QPalette::ColorGroup cg, QPalette::ColorRole cr) const
.
Returns true
if the ColorGroup cg and ColorRole cr has been set previously on this palette; otherwise returns false
.
This function was introduced in Qt 4.2.
See also setBrush().
Sourcepub unsafe fn is_copy_of(&self, p: impl CastInto<Ref<QPalette>>) -> bool
pub unsafe fn is_copy_of(&self, p: impl CastInto<Ref<QPalette>>) -> bool
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.
Calls C++ function: 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=() and operator==().
Sourcepub unsafe fn is_equal(&self, cr1: ColorGroup, cr2: ColorGroup) -> bool
pub unsafe fn is_equal(&self, cr1: ColorGroup, cr2: ColorGroup) -> bool
Returns true
(usually quickly) if color group cg1 is equal to cg2; otherwise returns false
.
Calls C++ function: bool QPalette::isEqual(QPalette::ColorGroup cr1, QPalette::ColorGroup cr2) const
.
Returns true
(usually quickly) if color group cg1 is equal to cg2; otherwise returns false
.
Sourcepub unsafe fn light(&self) -> Ref<QBrush>
pub unsafe fn light(&self) -> Ref<QBrush>
Returns the light brush of the current color group.
Calls C++ function: const QBrush& QPalette::light() const
.
Sourcepub unsafe fn link(&self) -> Ref<QBrush>
pub unsafe fn link(&self) -> Ref<QBrush>
Returns the unvisited link text brush of the current color group.
Calls C++ function: const QBrush& QPalette::link() const
.
Sourcepub unsafe fn link_visited(&self) -> Ref<QBrush>
pub unsafe fn link_visited(&self) -> Ref<QBrush>
Returns the visited link text brush of the current color group.
Calls C++ function: const QBrush& QPalette::linkVisited() const
.
Sourcepub unsafe fn mid(&self) -> Ref<QBrush>
pub unsafe fn mid(&self) -> Ref<QBrush>
Returns the mid brush of the current color group.
Calls C++ function: const QBrush& QPalette::mid() const
.
Sourcepub unsafe fn midlight(&self) -> Ref<QBrush>
pub unsafe fn midlight(&self) -> Ref<QBrush>
Returns the midlight brush of the current color group.
Calls C++ function: const QBrush& QPalette::midlight() const
.
Sourcepub unsafe fn new() -> CppBox<QPalette>
pub unsafe fn new() -> CppBox<QPalette>
Constructs a palette object that uses the application's default palette.
Calls C++ function: [constructor] void QPalette::QPalette()
.
Constructs a palette object that uses the application’s default palette.
See also QApplication::setPalette() and QApplication::palette().
Sourcepub unsafe fn from_q_color(
button: impl CastInto<Ref<QColor>>,
) -> CppBox<QPalette>
pub unsafe fn from_q_color( button: impl CastInto<Ref<QColor>>, ) -> CppBox<QPalette>
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.
Calls C++ function: [constructor] void 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.
Sourcepub unsafe fn from_global_color(button: GlobalColor) -> CppBox<QPalette>
pub unsafe fn from_global_color(button: GlobalColor) -> CppBox<QPalette>
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.
Calls C++ function: [constructor] void 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.
Sourcepub unsafe fn from_2_q_color(
button: impl CastInto<Ref<QColor>>,
window: impl CastInto<Ref<QColor>>,
) -> CppBox<QPalette>
pub unsafe fn from_2_q_color( button: impl CastInto<Ref<QColor>>, window: impl CastInto<Ref<QColor>>, ) -> CppBox<QPalette>
Constructs a palette from a button color and a window. The other colors are automatically calculated, based on these colors.
Calls C++ function: [constructor] void 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.
Sourcepub unsafe fn from_9_q_brush(
window_text: impl CastInto<Ref<QBrush>>,
button: impl CastInto<Ref<QBrush>>,
light: impl CastInto<Ref<QBrush>>,
dark: impl CastInto<Ref<QBrush>>,
mid: impl CastInto<Ref<QBrush>>,
text: impl CastInto<Ref<QBrush>>,
bright_text: impl CastInto<Ref<QBrush>>,
base: impl CastInto<Ref<QBrush>>,
window: impl CastInto<Ref<QBrush>>,
) -> CppBox<QPalette>
pub unsafe fn from_9_q_brush( window_text: impl CastInto<Ref<QBrush>>, button: impl CastInto<Ref<QBrush>>, light: impl CastInto<Ref<QBrush>>, dark: impl CastInto<Ref<QBrush>>, mid: impl CastInto<Ref<QBrush>>, text: impl CastInto<Ref<QBrush>>, bright_text: impl CastInto<Ref<QBrush>>, base: impl CastInto<Ref<QBrush>>, window: impl CastInto<Ref<QBrush>>, ) -> CppBox<QPalette>
Constructs a palette. You can pass either brushes, pixmaps or plain colors for windowText, button, light, dark, mid, text, bright_text, base and window.
Calls C++ function: [constructor] void 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.
Sourcepub unsafe fn from_7_q_color(
window_text: impl CastInto<Ref<QColor>>,
window: impl CastInto<Ref<QColor>>,
light: impl CastInto<Ref<QColor>>,
dark: impl CastInto<Ref<QColor>>,
mid: impl CastInto<Ref<QColor>>,
text: impl CastInto<Ref<QColor>>,
base: impl CastInto<Ref<QColor>>,
) -> CppBox<QPalette>
pub unsafe fn from_7_q_color( window_text: impl CastInto<Ref<QColor>>, window: impl CastInto<Ref<QColor>>, light: impl CastInto<Ref<QColor>>, dark: impl CastInto<Ref<QColor>>, mid: impl CastInto<Ref<QColor>>, text: impl CastInto<Ref<QColor>>, base: impl CastInto<Ref<QColor>>, ) -> CppBox<QPalette>
Calls C++ function: [constructor] void QPalette::QPalette(const QColor& windowText, const QColor& window, const QColor& light, const QColor& dark, const QColor& mid, const QColor& text, const QColor& base)
.
Sourcepub unsafe fn new_copy(
palette: impl CastInto<Ref<QPalette>>,
) -> CppBox<QPalette>
pub unsafe fn new_copy( palette: impl CastInto<Ref<QPalette>>, ) -> CppBox<QPalette>
Constructs a copy of p.
Calls C++ function: [constructor] void QPalette::QPalette(const QPalette& palette)
.
Constructs a copy of p.
This constructor is fast thanks to implicit sharing.
Sourcepub unsafe fn placeholder_text(&self) -> Ref<QBrush>
Available on cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.
pub unsafe fn placeholder_text(&self) -> Ref<QBrush>
cpp_lib_version="5.12.2"
or cpp_lib_version="5.13.0"
or cpp_lib_version="5.14.0"
only.Returns the placeholder text brush of the current color group.
Calls C++ function: const QBrush& QPalette::placeholderText() const
.
Returns the placeholder text brush of the current color group.
Note: Before Qt 5.12, the placeholder text color was hard-coded in the code as QPalette::text().color() where an alpha of 128 was applied. We continue to support this behavior by default, unless you set your own brush. One can get back the original placeholder color setting the special QBrush default constructor as placeholder brush.
This function was introduced in Qt 5.12.
Sourcepub unsafe fn resolve_1a(
&self,
arg1: impl CastInto<Ref<QPalette>>,
) -> CppBox<QPalette>
pub unsafe fn resolve_1a( &self, arg1: impl CastInto<Ref<QPalette>>, ) -> CppBox<QPalette>
Sourcepub unsafe fn resolve_0a(&self) -> c_uint
pub unsafe fn resolve_0a(&self) -> c_uint
Returns a new QPalette that has attributes copied from other.
Calls C++ function: unsigned int QPalette::resolve() const
.
Warning: no exact match found in C++ documentation. Below is the C++ documentation for QPalette QPalette::resolve(const QPalette &other) const
:
Returns a new QPalette that has attributes copied from other.
Sourcepub unsafe fn resolve_1a_mut(&self, mask: c_uint)
pub unsafe fn resolve_1a_mut(&self, mask: c_uint)
Returns a new QPalette that has attributes copied from other.
Calls C++ function: void QPalette::resolve(unsigned int mask)
.
Warning: no exact match found in C++ documentation. Below is the C++ documentation for QPalette QPalette::resolve(const QPalette &other) const
:
Returns a new QPalette that has attributes copied from other.
Sourcepub unsafe fn set_brush_2a(
&self,
cr: ColorRole,
brush: impl CastInto<Ref<QBrush>>,
)
pub unsafe fn set_brush_2a( &self, cr: ColorRole, brush: impl CastInto<Ref<QBrush>>, )
Sets the brush for the given color role to the specified brush for all groups in the palette.
Calls C++ function: void QPalette::setBrush(QPalette::ColorRole cr, const QBrush& brush)
.
Sourcepub unsafe fn set_brush_3a(
&self,
cg: ColorGroup,
cr: ColorRole,
brush: impl CastInto<Ref<QBrush>>,
)
pub unsafe fn set_brush_3a( &self, cg: ColorGroup, cr: ColorRole, brush: impl CastInto<Ref<QBrush>>, )
This is an overloaded function.
Calls C++ function: void QPalette::setBrush(QPalette::ColorGroup cg, QPalette::ColorRole cr, const QBrush& brush)
.
Sourcepub unsafe fn set_color_3a(
&self,
cg: ColorGroup,
cr: ColorRole,
color: impl CastInto<Ref<QColor>>,
)
pub unsafe fn set_color_3a( &self, cg: ColorGroup, cr: ColorRole, color: impl CastInto<Ref<QColor>>, )
Sets the color in the specified color group, used for the given color role, to the specified solid color.
Calls C++ function: void QPalette::setColor(QPalette::ColorGroup cg, QPalette::ColorRole cr, const QColor& color)
.
Sourcepub unsafe fn set_color_2a(
&self,
cr: ColorRole,
color: impl CastInto<Ref<QColor>>,
)
pub unsafe fn set_color_2a( &self, cr: ColorRole, color: impl CastInto<Ref<QColor>>, )
This is an overloaded function.
Calls C++ function: void QPalette::setColor(QPalette::ColorRole cr, const QColor& color)
.
Sourcepub unsafe fn set_color_group(
&self,
cr: ColorGroup,
window_text: impl CastInto<Ref<QBrush>>,
button: impl CastInto<Ref<QBrush>>,
light: impl CastInto<Ref<QBrush>>,
dark: impl CastInto<Ref<QBrush>>,
mid: impl CastInto<Ref<QBrush>>,
text: impl CastInto<Ref<QBrush>>,
bright_text: impl CastInto<Ref<QBrush>>,
base: impl CastInto<Ref<QBrush>>,
window: impl CastInto<Ref<QBrush>>,
)
pub unsafe fn set_color_group( &self, cr: ColorGroup, window_text: impl CastInto<Ref<QBrush>>, button: impl CastInto<Ref<QBrush>>, light: impl CastInto<Ref<QBrush>>, dark: impl CastInto<Ref<QBrush>>, mid: impl CastInto<Ref<QBrush>>, text: impl CastInto<Ref<QBrush>>, bright_text: impl CastInto<Ref<QBrush>>, base: impl CastInto<Ref<QBrush>>, window: impl CastInto<Ref<QBrush>>, )
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.
Calls C++ function: void QPalette::setColorGroup(QPalette::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. You can pass either brushes, pixmaps or plain colors for windowText, button, light, dark, mid, text, bright_text, base and window.
See also QBrush.
Sourcepub unsafe fn set_current_color_group(&self, cg: ColorGroup)
pub unsafe fn set_current_color_group(&self, cg: ColorGroup)
Set the palette's current color group to cg.
Calls C++ function: void QPalette::setCurrentColorGroup(QPalette::ColorGroup cg)
.
Set the palette’s current color group to cg.
See also currentColorGroup().
Sourcepub unsafe fn shadow(&self) -> Ref<QBrush>
pub unsafe fn shadow(&self) -> Ref<QBrush>
Returns the shadow brush of the current color group.
Calls C++ function: const QBrush& QPalette::shadow() const
.
Sourcepub unsafe fn static_meta_object() -> Ref<QMetaObject>
pub unsafe fn static_meta_object() -> Ref<QMetaObject>
Returns a reference to the staticMetaObject
field.
Sourcepub unsafe fn swap(&self, other: impl CastInto<Ref<QPalette>>)
pub unsafe fn swap(&self, other: impl CastInto<Ref<QPalette>>)
Swaps this palette instance with other. This function is very fast and never fails.
Calls C++ function: 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.
Sourcepub unsafe fn text(&self) -> Ref<QBrush>
pub unsafe fn text(&self) -> Ref<QBrush>
Returns the text foreground brush of the current color group.
Calls C++ function: const QBrush& QPalette::text() const
.
Sourcepub unsafe fn to_q_variant(&self) -> CppBox<QVariant>
pub unsafe fn to_q_variant(&self) -> CppBox<QVariant>
Sourcepub unsafe fn tool_tip_base(&self) -> Ref<QBrush>
pub unsafe fn tool_tip_base(&self) -> Ref<QBrush>
Returns the tool tip base brush of the current color group. This brush is used by QToolTip and QWhatsThis.
Calls C++ function: const QBrush& QPalette::toolTipBase() const
.
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.
This function was introduced in Qt 4.4.
Sourcepub unsafe fn tool_tip_text(&self) -> Ref<QBrush>
pub unsafe fn tool_tip_text(&self) -> Ref<QBrush>
Returns the tool tip text brush of the current color group. This brush is used by QToolTip and QWhatsThis.
Calls C++ function: const QBrush& QPalette::toolTipText() const
.
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.
This function was introduced in Qt 4.4.
Sourcepub unsafe fn window(&self) -> Ref<QBrush>
pub unsafe fn window(&self) -> Ref<QBrush>
Returns the window (general background) brush of the current color group.
Calls C++ function: const QBrush& QPalette::window() const
.
Sourcepub unsafe fn window_text(&self) -> Ref<QBrush>
pub unsafe fn window_text(&self) -> Ref<QBrush>
Returns the window text (general foreground) brush of the current color group.
Calls C++ function: const QBrush& QPalette::windowText() const
.
Trait Implementations§
Source§impl CppDeletable for QPalette
impl CppDeletable for QPalette
Source§impl PartialEq<Ref<QPalette>> for QPalette
impl PartialEq<Ref<QPalette>> for QPalette
Source§fn eq(&self, p: &Ref<QPalette>) -> bool
fn eq(&self, p: &Ref<QPalette>) -> bool
Returns true
(usually quickly) if this palette is equal to p; otherwise returns false
(slowly).
Calls C++ function: 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!=().