def
__eq__
(p)
def
__ne__
(p)
def
alternateBase
()
def
background
()
def
base
()
def
brightText
()
def
brush
(cg, cr)
def
brush
(cr)
def
button
()
def
buttonText
()
def
cacheKey
()
def
color
(cg, cr)
def
color
(cr)
def
currentColorGroup
()
def
dark
()
def
foreground
()
def
highlight
()
def
highlightedText
()
def
isBrushSet
(cg, cr)
def
isCopyOf
(p)
def
isEqual
(cr1, cr2)
def
light
()
def
link
()
def
linkVisited
()
def
mid
()
def
midlight
()
def
placeholderText
()
def
resolve
()
def
resolve
(arg__1)
def
resolve
(mask)
def
setBrush
(cg, cr, brush)
def
setBrush
(cr, brush)
def
setColor
(cg, cr, color)
def
setColor
(cr, color)
def
setColorGroup
(cr, windowText, button, light, dark, mid, text, bright_text, base, window)
def
setCurrentColorGroup
(cg)
def
shadow
()
def
swap
(other)
def
text
()
def
toolTipBase
()
def
toolTipText
()
def
window
()
def
windowText
()
A palette consists of three color groups: Active , Disabled ,和 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()andsetBrush(). 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 theColorRole文档编制。We strongly recommend that you use the default palette of the current style (returned by
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()andsetBrush(), depending on whether you want a pure color or a pixmap pattern.There are also corresponding
color()andbrush()getters, and a commonly used convenience function to get theColorRolefor the currentColorGroup:window(),windowText(),base(),等。You can copy a palette using the copy constructor and test to see if two palettes are identical 使用
isCopyOf().
QPaletteis optimized by the use of 隐式共享 , so it is very efficient to passQPaletteobjects as arguments.警告
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.
另请参阅
setPalette()setPalette()QColor
QPalette
¶
QPalette(button)
QPalette(windowText, button, light, dark, mid, text, bright_text, base, window)
QPalette(button)
QPalette(button, window)
QPalette(windowText, window, light, dark, mid, text, base)
QPalette(palette)
Constructs a palette object that uses the application’s default palette.
另请参阅
setPalette()
palette()
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.
Constructs a palette. You can pass either brushes, pixmaps or plain colors for
windowText
,
button
,
light
,
dark
,
mid
,
text
,
bright_text
,
base
and
window
.
另请参阅
Constructs a palette from a
button
color and a
window
. The other colors are automatically calculated, based on these colors.
Constructs a palette with the specified
windowText
,
window
,
light
,
dark
,
mid
,
text
,和
base
colors. The button color will be set to the window color.
PySide2.QtGui.QPalette.
ColorGroup
¶
|
常量 |
描述 |
|---|---|
|
QPalette.Disabled |
|
|
QPalette.Active |
|
|
QPalette.Inactive |
|
|
QPalette.Normal |
synonym for Active |
PySide2.QtGui.QPalette.
ColorRole
¶
The enum defines the different symbolic color roles used in current GUIs.
The central roles are:
|
常量 |
描述 |
|---|---|
|
QPalette.Window |
A general background color. |
|
QPalette.Background |
This value is obsolete. Use Window instead. |
|
QPalette.WindowText |
A general foreground color. |
|
QPalette.Foreground |
This value is obsolete. Use instead. |
|
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
|
|
QPalette.ToolTipBase |
Used as the background color for
|
|
QPalette.ToolTipText |
Used as the foreground color for
|
|
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
|
|
QPalette.Button |
The general button background color. This background can be different from
|
|
QPalette.ButtonText |
A foreground color used with the
|
|
QPalette.BrightText |
A text color that is very different from
|
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
Mid
to be slightly different from
Window
.
|
常量 |
描述 |
|---|---|
|
QPalette.Light |
Lighter than
|
|
QPalette.Midlight |
Between
|
|
QPalette.Dark |
Darker than
|
|
QPalette.Mid |
Between
|
|
QPalette.Shadow |
A very dark color. By default, the shadow color is
|
Selected (marked) items have two roles:
|
常量 |
描述 |
|---|---|
|
QPalette.Highlight |
A color to indicate a selected item or the current item. By default, the highlight color is
|
|
QPalette.HighlightedText |
A text color that contrasts with
|
There are two color roles related to hyperlinks:
|
常量 |
描述 |
|---|---|
|
QPalette.Link |
A text color used for unvisited hyperlinks. By default, the link color is
|
|
QPalette.LinkVisited |
A text color used for already visited hyperlinks. By default, the linkvisited color is
|
Note that we do not use the
Link
and
LinkVisited
roles 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)
sheet = QString.fromLatin1("a { text-decoration: underline color: %1 }").arg(linkColor.name())
browser.document().setDefaultStyleSheet(sheet)
|
常量 |
描述 |
|---|---|
|
QPalette.NoRole |
No role; this special role is often used to indicate that a role has not been assigned. |
PySide2.QtGui.QPalette.
alternateBase
(
)
¶
Returns the alternate base brush of the current color group.
另请参阅
ColorRole
brush()
PySide2.QtGui.QPalette.
base
(
)
¶
Returns the base brush of the current color group.
另请参阅
ColorRole
brush()
PySide2.QtGui.QPalette.
brightText
(
)
¶
Returns the bright text foreground brush of the current color group.
另请参阅
ColorRole
brush()
PySide2.QtGui.QPalette.
brush
(
cg
,
cr
)
¶
cg
–
ColorGroup
cr
–
ColorRole
Returns the brush in the specified color
group
, used for the given color
role
.
另请参阅
color()
setBrush()
ColorRole
PySide2.QtGui.QPalette.
brush
(
cr
)
¶
这是重载函数。
Returns the brush that has been set for the given color
role
in the current
ColorGroup
.
另请参阅
color()
setBrush()
ColorRole
Returns the button text foreground brush of the current color group.
另请参阅
ColorRole
brush()
PySide2.QtGui.QPalette.
cacheKey
(
)
¶
qint64
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 will change when the palette is altered.
PySide2.QtGui.QPalette.
color
(
cg
,
cr
)
¶
cg
–
ColorGroup
cr
–
ColorRole
Returns the color in the specified color
group
, used for the given color
role
.
另请参阅
brush()
setColor()
ColorRole
PySide2.QtGui.QPalette.
color
(
cr
)
¶
这是重载函数。
Returns the color that has been set for the given color
role
in the current
ColorGroup
.
另请参阅
brush()
ColorRole
PySide2.QtGui.QPalette.
currentColorGroup
(
)
¶
Returns the palette’s current color group.
PySide2.QtGui.QPalette.
dark
(
)
¶
Returns the dark brush of the current color group.
另请参阅
ColorRole
brush()
PySide2.QtGui.QPalette.
foreground
(
)
¶
注意
此函数被弃用。
使用
windowText()
代替。
PySide2.QtGui.QPalette.
highlight
(
)
¶
Returns the highlight brush of the current color group.
另请参阅
ColorRole
brush()
PySide2.QtGui.QPalette.
highlightedText
(
)
¶
Returns the highlighted text brush of the current color group.
另请参阅
ColorRole
brush()
PySide2.QtGui.QPalette.
isBrushSet
(
cg
,
cr
)
¶
cg
–
ColorGroup
cr
–
ColorRole
bool
返回
true
若
ColorGroup
cg
and
ColorRole
cr
has been set previously on this palette; otherwise returns
false
.
另请参阅
PySide2.QtGui.QPalette.
isCopyOf
(
p
)
¶
p
–
QPalette
bool
返回
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.
另请参阅
operator=()
operator==()
PySide2.QtGui.QPalette.
isEqual
(
cr1
,
cr2
)
¶
cr1
–
ColorGroup
cr2
–
ColorGroup
bool
返回
true
(usually quickly) if color group
cg1
等于
cg2
;否则返回
false
.
PySide2.QtGui.QPalette.
light
(
)
¶
Returns the light brush of the current color group.
另请参阅
ColorRole
brush()
PySide2.QtGui.QPalette.
link
(
)
¶
Returns the unvisited link text brush of the current color group.
另请参阅
ColorRole
brush()
PySide2.QtGui.QPalette.
linkVisited
(
)
¶
Returns the visited link text brush of the current color group.
另请参阅
ColorRole
brush()
PySide2.QtGui.QPalette.
mid
(
)
¶
Returns the mid brush of the current color group.
另请参阅
ColorRole
brush()
PySide2.QtGui.QPalette.
midlight
(
)
¶
Returns the midlight brush of the current color group.
另请参阅
ColorRole
brush()
PySide2.QtGui.QPalette.
__ne__
(
p
)
¶
p
–
QPalette
bool
返回
true
(slowly) if this palette is different from
p
;否则返回
false
(usually quickly).
注意
The current
ColorGroup
is not taken into account when comparing palettes
另请参阅
operator==()
PySide2.QtGui.QPalette.
__eq__
(
p
)
¶
p
–
QPalette
bool
返回
true
(usually quickly) if this palette is equal to
p
;否则返回
false
(slowly).
注意
The current
ColorGroup
is not taken into account when comparing palettes
另请参阅
operator!=()
PySide2.QtGui.QPalette.
placeholderText
(
)
¶
Returns the placeholder text brush of the current color group.
注意
Before Qt 5.12, the placeholder text color was hard-coded in the code as
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.
另请参阅
ColorRole
brush()
PySide2.QtGui.QPalette.
resolve
(
)
¶
uint
PySide2.QtGui.QPalette.
resolve
(
arg__1
)
¶
返回新
QPalette
that is a union of this instance and
other
. Color roles set in this instance take precedence.
PySide2.QtGui.QPalette.
resolve
(
mask
)
¶
mask
–
uint
PySide2.QtGui.QPalette.
setBrush
(
cr
,
brush
)
¶
Sets the brush for the given color
role
到指定
brush
for all groups in the palette.
另请参阅
brush()
setColor()
ColorRole
PySide2.QtGui.QPalette.
setBrush
(
cg
,
cr
,
brush
)
¶
cg
–
ColorGroup
cr
–
ColorRole
brush
–
QBrush
这是重载函数。
Sets the brush in the specified color
group
, used for the given color
role
,到
brush
.
另请参阅
brush()
setColor()
ColorRole
PySide2.QtGui.QPalette.
setColor
(
cg
,
cr
,
color
)
¶
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
.
另请参阅
setBrush()
color()
ColorRole
PySide2.QtGui.QPalette.
setColor
(
cr
,
color
)
¶
这是重载函数。
Sets the color used for the given color
role
, in all color groups, to the specified solid
color
.
另请参阅
brush()
setColor()
ColorRole
PySide2.QtGui.QPalette.
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
,
base
and
window
.
另请参阅
PySide2.QtGui.QPalette.
setCurrentColorGroup
(
cg
)
¶
cg
–
ColorGroup
Set the palette’s current color group to
cg
.
另请参阅
PySide2.QtGui.QPalette.
shadow
(
)
¶
Returns the shadow brush of the current color group.
另请参阅
ColorRole
brush()
PySide2.QtGui.QPalette.
swap
(
other
)
¶
other
–
QPalette
Swaps this palette instance with
other
。此函数非常快,且从不失败。
PySide2.QtGui.QPalette.
text
(
)
¶
Returns the text foreground brush of the current color group.
另请参阅
ColorRole
brush()
PySide2.QtGui.QPalette.
toolTipBase
(
)
¶
Returns the tool tip base brush of the current color group. This brush is used by
QToolTip
and
QWhatsThis
.
注意
Tool tips use the Inactive color group of
QPalette
, because tool tips are not active windows.
另请参阅
ColorRole
brush()
PySide2.QtGui.QPalette.
toolTipText
(
)
¶
Returns the tool tip text brush of the current color group. This brush is used by
QToolTip
and
QWhatsThis
.
注意
Tool tips use the Inactive color group of
QPalette
, because tool tips are not active windows.
另请参阅
ColorRole
brush()