PySide6.QtGui.QPalette¶
- class QPalette¶
- The - QPaletteclass contains color groups for each widget state. More…- Synopsis¶- Methods¶- def - __init__()
- def - accent()
- def - alternateBase()
- def - base()
- def - brightText()
- def - brush()
- def - button()
- def - buttonText()
- def - cacheKey()
- def - color()
- def - dark()
- def - highlight()
- def - isBrushSet()
- def - isCopyOf()
- def - isEqual()
- def - light()
- def - link()
- def - linkVisited()
- def - mid()
- def - midlight()
- def - __ne__()
- def - __eq__()
- def - resolve()
- def - resolveMask()
- def - setBrush()
- def - setColor()
- def - setColorGroup()
- def - setResolveMask()
- def - shadow()
- def - swap()
- def - text()
- def - toolTipBase()
- def - toolTipText()
- def - window()
- def - windowText()
 - Note - This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE - Detailed Description¶- 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- ColorRoledocumentation.- 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- ColorRolefor 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().- QPaletteis optimized by the use of implicit sharing, so it is very efficient to pass- QPaletteobjects 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 - class ColorGroup¶
- Constant - Description - QPalette.Disabled - QPalette.Active - QPalette.Inactive - QPalette.Normal - synonym for Active 
 - class ColorRole¶
- Warning - This section contains snippets that were automatically translated from C++ to Python and may contain errors.   - The ColorRole enum defines the different symbolic color roles used in current GUIs. - The central roles are: - Constant - Description - QPalette.Window - A general background color. - QPalette.WindowText - A general foreground color. - QPalette.Base - Used mostly as the background color for text entry widgets, but can also be used for other painting - such as the background of combobox drop down lists and toolbar handles. It is usually white or another light color. - QPalette.AlternateBase - Used as the alternate background color in views with alternating row colors (see QAbstractItemView::setAlternatingRowColors()). - QPalette.ToolTipBase - Used as the background color for QToolTip and QWhatsThis. Tool tips use the Inactive color group of - QPalette, because tool tips are not active windows.- QPalette.ToolTipText - Used as the foreground color for QToolTip and QWhatsThis. Tool tips use the Inactive color group of - QPalette, because tool tips are not active windows.- QPalette.PlaceholderText - Used as the placeholder color for various text input widgets. This enum value has been introduced in Qt 5.12 - QPalette.Text - The foreground color used with - Base. This is usually the same as the- WindowText, in which case it must provide good contrast with- Windowand- Base.- QPalette.Button - The general button background color. This background can be different from - Windowas some styles require a different background color for buttons.- QPalette.ButtonText - A foreground color used with the - Buttoncolor.- QPalette.BrightText - A text color that is very different from - WindowText, and contrasts well with e.g.- Dark. Typically used for text that needs to be drawn where- Textor- WindowTextwould give poor contrast, such as on pressed push buttons. Note that text colors can be used for things other than just words; text colors are usually used for text, but it’s quite common to use the text color roles for lines, icons, etc.- There are some color roles used mostly for 3D bevel and shadow effects. All of these are normally derived from - Window, and used in ways that depend on that relationship. For example, buttons depend on it to make the bevels look attractive, and Motif scroll bars depend on- Midto be slightly different from- Window.- Constant - Description - QPalette.Light - Lighter than - Buttoncolor.- QPalette.Midlight - Between - Buttonand- Light.- QPalette.Dark - Darker than - Button.- QPalette.Mid - Between - Buttonand- Dark.- QPalette.Shadow - A very dark color. By default, the shadow color is Qt::black. - Selected (marked) items have two roles: - Constant - Description - QPalette.Highlight - A color to indicate a selected item or the current item. By default, the highlight color is Qt::darkBlue. - QPalette.Accent - A color that typically contrasts or complements Base, Window and Button colors. It usually represents the users’ choice of desktop personalisation. Styling of interactive components is a typical use case. Unless explicitly set, it defaults to Highlight. - QPalette.HighlightedText - A text color that contrasts with - Highlight. By default, the highlighted text color is Qt::white.- There are two color roles related to hyperlinks: - Constant - Description - QPalette.Link - A text color used for unvisited hyperlinks. By default, the link color is Qt::blue. - QPalette.LinkVisited - A text color used for already visited hyperlinks. By default, the linkvisited color is Qt::magenta. - Note that we do not use the - Linkand- LinkVisitedroles when rendering rich text in Qt, and that we recommend that you use CSS and the- setDefaultStyleSheet()function to alter the appearance of links. For example:- browser = QTextBrowser() linkColor = QColor(Qt.red) QString sheet = "a { text-decoration: underline; color: %1 }".arg(linkColor.name()) browser.document().setDefaultStyleSheet(sheet) - Constant - Description - QPalette.NoRole - No role; this special role is often used to indicate that a role has not been assigned. 
 - __init__()¶
 - Constructs an empty palette object with no color roles set. - When used as the palette of a QWidget the colors are resolved as described by QWidget::setPalette(). - See also - palette()- __init__(button)
- Parameters:
- button – - GlobalColor
 
 - Constructs a palette from the - buttoncolor. The other colors are automatically calculated, based on this color.- Windowwill be the button color as well.- __init__(button)
- Parameters:
- button – - QColor
 
 - Constructs a palette from the - buttoncolor. The other colors are automatically calculated, based on this color.- Windowwill be the button color as well.- __init__(palette)
- Parameters:
- palette – - QPalette
 
 - Constructs a copy of - p.- This constructor is fast thanks to implicit sharing. - Constructs a palette from a - buttoncolor and a- window. The other colors are automatically calculated, based on these colors.- __init__(windowText, window, light, dark, mid, text, base)
 - Constructs a palette with the specified - windowText,- window,- light,- dark,- mid,- text, and- basecolors. The button color will be set to the window color.- __init__(windowText, button, light, dark, mid, text, bright_text, base, window)
 - Constructs a palette. You can pass either brushes, pixmaps or plain colors for - windowText,- button,- light,- dark,- mid,- text,- bright_text,- baseand- window.- See also - Returns the accent brush of the current color group. - Returns the alternate base brush of the current color group. - Returns the base brush of the current color group. - Returns the bright text foreground brush of the current color group. - This is an overloaded function. - Returns the brush that has been set for the given color - rolein the current- ColorGroup.- See also - brush(cg, cr)
- Parameters:
- cg – - ColorGroup
- cr – - ColorRole
 
- Return type:
 
 - Returns the brush in the specified color - group, used for the given color- role.- See also - Returns the button brush of the current color group. - Returns the button text foreground brush of the current color group. - cacheKey()¶
- Return type:
- int 
 
 - Returns a number that identifies the contents of this - QPaletteobject. Distinct- QPaletteobjects can have the same key if they refer to the same contents.- The cacheKey() will change when the palette is altered. - This is an overloaded function. - Returns the color that has been set for the given color - rolein the current- ColorGroup.- color(cg, cr)
- Parameters:
- cg – - ColorGroup
- cr – - ColorRole
 
- Return type:
 
 - Returns the color in the specified color - group, used for the given color- role.- See also - currentColorGroup()¶
- Return type:
 
 - Returns the palette’s current color group. - See also - Returns the dark brush of the current color group. - Returns the highlight brush of the current color group. - Returns the highlighted text brush of the current color group. - isBrushSet(cg, cr)¶
- Parameters:
- cg – - ColorGroup
- cr – - ColorRole
 
- Return type:
- bool 
 
 - Returns - trueif the- ColorGroup- cgand- ColorRole- crhas been set previously on this palette; otherwise returns- false.- The - ColorGroup- cgshould be less than- NColorGroups, but you can use- Current. In this case, the previously set current color group will be used.- The - ColorRole- crshould be less than- NColorRoles.- See also - Returns - trueif this palette and- pare 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==()- isEqual(cr1, cr2)¶
- Parameters:
- cr1 – - ColorGroup
- cr2 – - ColorGroup
 
- Return type:
- bool 
 
 - Returns - true(usually quickly) if color group- cg1is equal to- cg2; otherwise returns- false.- Returns the light brush of the current color group. - Returns the unvisited link text brush of the current color group. - Returns the visited link text brush of the current color group. - Returns the mid brush of the current color group. - Returns the midlight brush of the current color group. - Returns - true(slowly) if this palette is different from- p; otherwise returns- false(usually quickly).- Returns - true(usually quickly) if this palette is equal to- p; otherwise returns- false(slowly).- Note - The following is not taken into account when comparing palettes: - the - current- ColorGroup
 - See also - operator!=()- Returns the placeholder text brush of the current color group. - Note - Before Qt 5.12, the placeholder text color was hard-coded as - text().- color()with an alpha of 128 applied. In Qt 6, it is an independent color.- Returns a new - QPalettethat is a union of this instance and- other. Color roles set in this instance take precedence. Roles that are not set in this instance will be taken from- other.- See also - resolveMask()¶
- Return type:
- int 
 
 - Sets the brush for the given color - roleto the specified- brushfor all groups in the palette.- See also - setBrush(cg, cr, brush)
- Parameters:
- cg – - ColorGroup
- cr – - ColorRole
- brush – - QBrush
 
 
 - This is an overloaded function. - Sets the brush in the specified color - group, used for the given color- role, to- brush.- See also - 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 - setColor(cg, cr, color)
- Parameters:
- cg – - ColorGroup
- cr – - ColorRole
- color – - QColor
 
 
 - Sets the color in the specified color - group, used for the given color- role, to the specified solid- color.- See also - setColorGroup(cr, windowText, button, light, dark, mid, text, bright_text, base, 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,- baseand- window.- See also - setCurrentColorGroup(cg)¶
- Parameters:
- cg – - ColorGroup
 
 - Set the palette’s current color group to - cg.- See also - setResolveMask(mask)¶
- Parameters:
- mask – int 
 
 - Returns the shadow brush of the current color group. - Swaps this palette instance with - other. This operation is very fast and never fails.- Returns the text foreground brush of the current color group. - 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.- 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.- Returns the window (general background) brush of the current color group. - Returns the window text (general foreground) brush of the current color group.