Struct qt_gui::QPalette

source ·
#[repr(C)]
pub struct QPalette { /* private fields */ }
Expand description

The QPalette class contains color groups for each widget state.

C++ class: QPalette.

C++ documentation:

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

source

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.

C++ documentation:

Returns the alternate base brush of the current color group.

See also ColorRole and brush().

source

pub unsafe fn background(&self) -> Ref<QBrush>

Use window() instead.

Calls C++ function: const QBrush& QPalette::background() const.

C++ documentation:

Use window() instead.

source

pub unsafe fn base(&self) -> Ref<QBrush>

Returns the base brush of the current color group.

Calls C++ function: const QBrush& QPalette::base() const.

C++ documentation:

Returns the base brush of the current color group.

See also ColorRole and brush().

source

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.

C++ documentation:

Returns the bright text foreground brush of the current color group.

See also ColorRole and brush().

source

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.

C++ documentation:

Returns the brush in the specified color group, used for the given color role.

See also color(), setBrush(), and ColorRole.

source

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.

C++ documentation:

This is an overloaded function.

Returns the brush that has been set for the given color role in the current ColorGroup.

See also color(), setBrush(), and ColorRole.

source

pub unsafe fn button(&self) -> Ref<QBrush>

Returns the button brush of the current color group.

Calls C++ function: const QBrush& QPalette::button() const.

C++ documentation:

Returns the button brush of the current color group.

See also ColorRole and brush().

source

pub unsafe fn button_text(&self) -> Ref<QBrush>

Returns the button text foreground brush of the current color group.

Calls C++ function: const QBrush& QPalette::buttonText() const.

C++ documentation:

Returns the button text foreground brush of the current color group.

See also ColorRole and brush().

source

pub unsafe 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.

Calls C++ function: qint64 QPalette::cacheKey() const.

C++ documentation:

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.

source

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.

C++ documentation:

Returns the color in the specified color group, used for the given color role.

See also brush(), setColor(), and ColorRole.

source

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.

C++ documentation:

This is an overloaded function.

Returns the color that has been set for the given color role in the current ColorGroup.

See also brush() and ColorRole.

source

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

C++ documentation:

Assigns p to this palette and returns a reference to this palette.

This operation is fast thanks to implicit sharing.

source

pub unsafe fn current_color_group(&self) -> ColorGroup

Returns the palette's current color group.

Calls C++ function: QPalette::ColorGroup QPalette::currentColorGroup() const.

C++ documentation:

Returns the palette’s current color group.

See also setCurrentColorGroup().

source

pub unsafe fn dark(&self) -> Ref<QBrush>

Returns the dark brush of the current color group.

Calls C++ function: const QBrush& QPalette::dark() const.

C++ documentation:

Returns the dark brush of the current color group.

See also ColorRole and brush().

source

pub unsafe fn foreground(&self) -> Ref<QBrush>

Use windowText() instead.

Calls C++ function: const QBrush& QPalette::foreground() const.

C++ documentation:

Use windowText() instead.

source

pub unsafe fn highlight(&self) -> Ref<QBrush>

Returns the highlight brush of the current color group.

Calls C++ function: const QBrush& QPalette::highlight() const.

C++ documentation:

Returns the highlight brush of the current color group.

See also ColorRole and brush().

source

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.

C++ documentation:

Returns the highlighted text brush of the current color group.

See also ColorRole and brush().

source

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.

C++ documentation:

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

source

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.

C++ documentation:

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

source

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.

C++ documentation:

Returns true (usually quickly) if color group cg1 is equal to cg2; otherwise returns false.

source

pub unsafe fn light(&self) -> Ref<QBrush>

Returns the light brush of the current color group.

Calls C++ function: const QBrush& QPalette::light() const.

C++ documentation:

Returns the light brush of the current color group.

See also ColorRole and brush().

Returns the unvisited link text brush of the current color group.

Calls C++ function: const QBrush& QPalette::link() const.

C++ documentation:

Returns the unvisited link text brush of the current color group.

See also ColorRole and brush().

Returns the visited link text brush of the current color group.

Calls C++ function: const QBrush& QPalette::linkVisited() const.

C++ documentation:

Returns the visited link text brush of the current color group.

See also ColorRole and brush().

source

pub unsafe fn mid(&self) -> Ref<QBrush>

Returns the mid brush of the current color group.

Calls C++ function: const QBrush& QPalette::mid() const.

C++ documentation:

Returns the mid brush of the current color group.

See also ColorRole and brush().

source

pub unsafe fn midlight(&self) -> Ref<QBrush>

Returns the midlight brush of the current color group.

Calls C++ function: const QBrush& QPalette::midlight() const.

C++ documentation:

Returns the midlight brush of the current color group.

See also ColorRole and brush().

source

pub unsafe fn new() -> CppBox<QPalette>

Constructs a palette object that uses the application's default palette.

Calls C++ function: [constructor] void QPalette::QPalette().

C++ documentation:

Constructs a palette object that uses the application’s default palette.

See also QApplication::setPalette() and QApplication::palette().

source

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

C++ documentation:

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.

source

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

C++ documentation:

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.

source

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

C++ documentation:

Constructs a palette from a button color and a window. The other colors are automatically calculated, based on these colors.

source

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

C++ documentation:

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.

source

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

source

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

C++ documentation:

Constructs a copy of p.

This constructor is fast thanks to implicit sharing.

source

pub 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.

Returns the placeholder text brush of the current color group.

Calls C++ function: const QBrush& QPalette::placeholderText() const.

C++ documentation:

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.

See also ColorRole and brush().

source

pub unsafe fn resolve_1a( &self, arg1: impl CastInto<Ref<QPalette>> ) -> CppBox<QPalette>

Returns a new QPalette that has attributes copied from other.

Calls C++ function: QPalette QPalette::resolve(const QPalette& arg1) const.

C++ documentation:

Returns a new QPalette that has attributes copied from other.

source

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.

source

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.

source

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

C++ documentation:

Sets the brush for the given color role to the specified brush for all groups in the palette.

See also brush(), setColor(), and ColorRole.

source

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

C++ documentation:

This is an overloaded function.

Sets the brush in the specified color group, used for the given color role, to brush.

See also brush(), setColor(), and ColorRole.

source

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

C++ documentation:

Sets the color in the specified color group, used for the given color role, to the specified solid color.

See also setBrush(), color(), and ColorRole.

source

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

C++ documentation:

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 brush(), setColor(), and ColorRole.

source

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

C++ documentation:

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.

source

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

C++ documentation:

Set the palette’s current color group to cg.

See also currentColorGroup().

source

pub unsafe fn shadow(&self) -> Ref<QBrush>

Returns the shadow brush of the current color group.

Calls C++ function: const QBrush& QPalette::shadow() const.

C++ documentation:

Returns the shadow brush of the current color group.

See also ColorRole and brush().

source

pub unsafe fn static_meta_object() -> Ref<QMetaObject>

Returns a reference to the staticMetaObject field.

source

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

C++ documentation:

Swaps this palette instance with other. This function is very fast and never fails.

This function was introduced in Qt 5.0.

source

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.

C++ documentation:

Returns the text foreground brush of the current color group.

See also ColorRole and brush().

source

pub unsafe fn to_q_variant(&self) -> CppBox<QVariant>

Returns the palette as a QVariant

Calls C++ function: QVariant QPalette::operator QVariant() const.

C++ documentation:

Returns the palette as a QVariant

source

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.

C++ documentation:

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.

See also ColorRole and brush().

source

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.

C++ documentation:

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.

See also ColorRole and brush().

source

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.

C++ documentation:

Returns the window (general background) brush of the current color group.

See also ColorRole and brush().

source

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.

C++ documentation:

Returns the window text (general foreground) brush of the current color group.

See also ColorRole and brush().

Trait Implementations§

source§

impl CppDeletable for QPalette

source§

unsafe fn delete(&self)

Destroys the palette.

Calls C++ function: [destructor] void QPalette::~QPalette().

C++ documentation:

Destroys the palette.

source§

impl PartialEq<Ref<QPalette>> for QPalette

source§

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.

C++ documentation:

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

1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T, U> CastInto<U> for T
where U: CastFrom<T>,

source§

unsafe fn cast_into(self) -> U

Performs the conversion. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> StaticUpcast<T> for T

source§

unsafe fn static_upcast(ptr: Ptr<T>) -> Ptr<T>

Convert type of a const pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.