pub struct Palette<'a> { /* private fields */ }
Expand description
Notice these docs are heavy WIP and not very relevent yet
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 and rather than literal colors like or . 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 Vista and the MacOS styles.
See also: Application::set_palette
Widget::set_palette
Color
Licence
The documentation is an adoption of the original Qt Documentation and provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation.
Implementations
sourceimpl<'a> Palette<'a>
impl<'a> Palette<'a>
pub fn new() -> Palette<'a>
sourcepub fn swap<P: PaletteTrait<'a>>(&self, other: &P) -> &Self
pub fn swap<P: PaletteTrait<'a>>(&self, other: &P) -> &Self
Swaps this palette instance with other. This function is very fast and never fails.
sourcepub fn current_color_group(&self) -> ColorGroup
pub fn current_color_group(&self) -> ColorGroup
Returns the palette’s current color group.
sourcepub fn set_current_color_group(&self, cg: ColorGroup) -> &Self
pub fn set_current_color_group(&self, cg: ColorGroup) -> &Self
Set the palette’s current color group to cg.
sourcepub fn color(&self, cg: ColorGroup, cr: ColorRole) -> Option<Color<'_>>
pub fn color(&self, cg: ColorGroup, cr: ColorRole) -> Option<Color<'_>>
Overloads Returns the color that has been set for the given color role in the current ColorGroup.
See also: [brush()
]
ColorRole
Returns the color in the specified color group, used for the given color role.
See also: [brush()
]
[set_color()
]
ColorRole
sourcepub fn brush(&self, cg: ColorGroup, cr: ColorRole) -> Option<Brush<'_>>
pub fn brush(&self, cg: ColorGroup, cr: ColorRole) -> Option<Brush<'_>>
Overloads Returns the brush that has been set for the given color role in the current ColorGroup.
See also: [color()
]
[set_brush()
]
ColorRole
Returns the brush in the specified color group, used for the given color role.
See also: [color()
]
[set_brush()
]
ColorRole
sourcepub fn set_color<C: ColorTrait<'a>>(
&self,
cg: ColorGroup,
cr: ColorRole,
color: &C
) -> &Self
pub fn set_color<C: ColorTrait<'a>>(
&self,
cg: ColorGroup,
cr: ColorRole,
color: &C
) -> &Self
Overloads Sets the color used for the given color role, in all color groups, to the specified solid color.
See also: [brush()
]
[set_color()
]
ColorRole
Sets the color in the specified color group, used for the given color role, to the specified solid color.
See also: [set_brush()
]
[color()
]
ColorRole
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: Brush
sourcepub fn set_color_2<C: ColorTrait<'a>>(&self, cr: ColorRole, color: &C) -> &Self
pub fn set_color_2<C: ColorTrait<'a>>(&self, cr: ColorRole, color: &C) -> &Self
Overloads Sets the color used for the given color role, in all color groups, to the specified solid color.
See also: [brush()
]
[set_color()
]
ColorRole
Sets the color in the specified color group, used for the given color role, to the specified solid color.
See also: [set_brush()
]
[color()
]
ColorRole
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: Brush
sourcepub fn set_brush<B: BrushTrait<'a>>(&self, cr: ColorRole, brush: &B) -> &Self
pub fn set_brush<B: BrushTrait<'a>>(&self, cr: ColorRole, brush: &B) -> &Self
Sets the brush for the given color role to the specified brush for all groups in the palette.
See also: [brush()
]
[set_color()
]
ColorRole
Overloads Sets the brush in the specified color group, used for the given color role, to brush.
See also: [brush()
]
[set_color()
]
ColorRole
sourcepub fn is_brush_set(&self, cg: ColorGroup, cr: ColorRole) -> bool
pub 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.
See also: [set_brush()
]
sourcepub fn set_brush_2<B: BrushTrait<'a>>(
&self,
cg: ColorGroup,
cr: ColorRole,
brush: &B
) -> &Self
pub fn set_brush_2<B: BrushTrait<'a>>(
&self,
cg: ColorGroup,
cr: ColorRole,
brush: &B
) -> &Self
Sets the brush for the given color role to the specified brush for all groups in the palette.
See also: [brush()
]
[set_color()
]
ColorRole
Overloads Sets the brush in the specified color group, used for the given color role, to brush.
See also: [brush()
]
[set_color()
]
ColorRole
sourcepub fn set_color_group<B: BrushTrait<'a>>(
&self,
cr: ColorGroup,
window_text: &B,
button: &B,
light: &B,
dark: &B,
mid: &B,
text: &B,
bright_text: &B,
base: &B,
window: &B
) -> &Self
pub fn set_color_group<B: BrushTrait<'a>>(
&self,
cr: ColorGroup,
window_text: &B,
button: &B,
light: &B,
dark: &B,
mid: &B,
text: &B,
bright_text: &B,
base: &B,
window: &B
) -> &Self
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: Brush
sourcepub fn is_equal(&self, cr1: ColorGroup, cr2: ColorGroup) -> bool
pub fn is_equal(&self, cr1: ColorGroup, cr2: ColorGroup) -> bool
Returns true
(usually quickly) if color group cg1 is equal to
cg2; otherwise returns false.
sourcepub fn color_2(&self, cr: ColorRole) -> Option<Color<'_>>
pub fn color_2(&self, cr: ColorRole) -> Option<Color<'_>>
Overloads Returns the color that has been set for the given color role in the current ColorGroup.
See also: [brush()
]
ColorRole
Returns the color in the specified color group, used for the given color role.
See also: [brush()
]
[set_color()
]
ColorRole
sourcepub fn brush_2(&self, cr: ColorRole) -> Option<Brush<'_>>
pub fn brush_2(&self, cr: ColorRole) -> Option<Brush<'_>>
Overloads Returns the brush that has been set for the given color role in the current ColorGroup.
See also: [color()
]
[set_brush()
]
ColorRole
Returns the brush in the specified color group, used for the given color role.
See also: [color()
]
[set_brush()
]
ColorRole
sourcepub fn foreground(&self) -> Option<Brush<'_>>
pub fn foreground(&self) -> Option<Brush<'_>>
Use windowText() instead.
sourcepub fn window_text(&self) -> Option<Brush<'_>>
pub fn window_text(&self) -> Option<Brush<'_>>
Returns the window text (general foreground) brush of the current color group.
See also: ColorRole
[brush()
]
Returns the button brush of the current color group.
See also: ColorRole
[brush()
]
Returns the button text foreground brush of the current color group.
See also: ColorRole
[brush()
]
sourcepub fn light(&self) -> Option<Brush<'_>>
pub fn light(&self) -> Option<Brush<'_>>
Returns the light brush of the current color group.
See also: ColorRole
[brush()
]
sourcepub fn dark(&self) -> Option<Brush<'_>>
pub fn dark(&self) -> Option<Brush<'_>>
Returns the dark brush of the current color group.
See also: ColorRole
[brush()
]
sourcepub fn mid(&self) -> Option<Brush<'_>>
pub fn mid(&self) -> Option<Brush<'_>>
Returns the midlight brush of the current color group.
See also: ColorRole
[brush()
]
Returns the mid brush of the current color group.
See also: ColorRole
[brush()
]
sourcepub fn text(&self) -> Option<Brush<'_>>
pub fn text(&self) -> Option<Brush<'_>>
Returns the text foreground brush of the current color group.
See also: ColorRole
[brush()
]
sourcepub fn base(&self) -> Option<Brush<'_>>
pub fn base(&self) -> Option<Brush<'_>>
Returns the base brush of the current color group.
See also: ColorRole
[brush()
]
sourcepub fn alternate_base(&self) -> Option<Brush<'_>>
pub fn alternate_base(&self) -> Option<Brush<'_>>
Returns the alternate base brush of the current color group.
See also: ColorRole
[brush()
]
sourcepub fn tool_tip_base(&self) -> Option<Brush<'_>>
pub fn tool_tip_base(&self) -> Option<Brush<'_>>
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()
]
sourcepub fn tool_tip_text(&self) -> Option<Brush<'_>>
pub fn tool_tip_text(&self) -> Option<Brush<'_>>
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()
]
sourcepub fn background(&self) -> Option<Brush<'_>>
pub fn background(&self) -> Option<Brush<'_>>
Use window() instead.
sourcepub fn window(&self) -> Option<Brush<'_>>
pub fn window(&self) -> Option<Brush<'_>>
Returns the window text (general foreground) brush of the current color group.
See also: ColorRole
[brush()
]
Returns the window (general background) brush of the current color group.
See also: ColorRole
[brush()
]
sourcepub fn midlight(&self) -> Option<Brush<'_>>
pub fn midlight(&self) -> Option<Brush<'_>>
Returns the midlight brush of the current color group.
See also: ColorRole
[brush()
]
sourcepub fn bright_text(&self) -> Option<Brush<'_>>
pub fn bright_text(&self) -> Option<Brush<'_>>
Returns the bright text foreground brush of the current color group.
See also: ColorRole
[brush()
]
Returns the button text foreground brush of the current color group.
See also: ColorRole
[brush()
]
sourcepub fn shadow(&self) -> Option<Brush<'_>>
pub fn shadow(&self) -> Option<Brush<'_>>
Returns the shadow brush of the current color group.
See also: ColorRole
[brush()
]
sourcepub fn highlight(&self) -> Option<Brush<'_>>
pub fn highlight(&self) -> Option<Brush<'_>>
Returns the highlight brush of the current color group.
See also: ColorRole
[brush()
]
Returns the highlighted text brush of the current color group.
See also: ColorRole
[brush()
]
sourcepub fn highlighted_text(&self) -> Option<Brush<'_>>
pub fn highlighted_text(&self) -> Option<Brush<'_>>
Returns the highlighted text brush of the current color group.
See also: ColorRole
[brush()
]
sourcepub fn link(&self) -> Option<Brush<'_>>
pub fn link(&self) -> Option<Brush<'_>>
Returns the unvisited link text brush of the current color group.
See also: ColorRole
[brush()
]
Returns the visited link text brush of the current color group.
See also: ColorRole
[brush()
]
sourcepub fn link_visited(&self) -> Option<Brush<'_>>
pub fn link_visited(&self) -> Option<Brush<'_>>
Returns the visited link text brush of the current color group.
See also: ColorRole
[brush()
]
sourcepub fn is_copy_of<P: PaletteTrait<'a>>(&self, p: &P) -> bool
pub fn is_copy_of<P: PaletteTrait<'a>>(&self, p: &P) -> 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.
See also: [operator()
]
[operator()
]
sourcepub fn cache_key(&self) -> i64
pub fn cache_key(&self) -> i64
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.
sourcepub fn resolve<P: PaletteTrait<'a>>(&self, arg0: &P) -> Palette<'_>
pub fn resolve<P: PaletteTrait<'a>>(&self, arg0: &P) -> Palette<'_>
Returns a new QPalette that has attributes copied from other.
sourcepub fn resolve_3(&self, mask: u32) -> &Self
pub fn resolve_3(&self, mask: u32) -> &Self
Returns a new QPalette that has attributes copied from other.