Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QPalette Class

TheQPalette class contains color groups for each widget state.More...

Header:#include <QPalette>
Inherited By:

QColorGroup

Public Types

enumColorGroup { Disabled, Active, Inactive, Normal }
enumColorRole { Window, Background, WindowText, Foreground, ..., NoRole }

Public Functions

QPalette()
QPalette(const QColor & button)
QPalette(Qt::GlobalColor button)
QPalette(const QColor & button, const QColor & window)
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)
QPalette(const QPalette & p)
~QPalette()
const QBrush &alternateBase() const
const QBrush &base() const
const QBrush &brightText() const
const QBrush &brush(ColorGroup group, ColorRole role) const
const QBrush &brush(ColorRole role) const
const QBrush &button() const
const QBrush &buttonText() const
qint64cacheKey() const
const QColor &color(ColorGroup group, ColorRole role) const
const QColor &color(ColorRole role) const
ColorGroupcurrentColorGroup() const
const QBrush &dark() const
const QBrush &highlight() const
const QBrush &highlightedText() const
boolisBrushSet(ColorGroup cg, ColorRole cr) const
boolisCopyOf(const QPalette & p) const
boolisEqual(ColorGroup cg1, ColorGroup cg2) const
const QBrush &light() const
const QBrush &link() const
const QBrush &linkVisited() const
const QBrush &mid() const
const QBrush &midlight() const
QPaletteresolve(const QPalette & other) const
voidsetBrush(ColorRole role, const QBrush & brush)
voidsetBrush(ColorGroup group, ColorRole role, const QBrush & brush)
voidsetColor(ColorGroup group, ColorRole role, const QColor & color)
voidsetColor(ColorRole role, const QColor & color)
voidsetColorGroup(ColorGroup cg, 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)
voidsetCurrentColorGroup(ColorGroup cg)
const QBrush &shadow() const
const QBrush &text() const
const QBrush &toolTipBase() const
const QBrush &toolTipText() const
const QBrush &window() const
const QBrush &windowText() const
operator QVariant() const
booloperator!=(const QPalette & p) const
QPalette &operator=(const QPalette & p)
QPalette &operator=(QPalette && other)
booloperator==(const QPalette & p) const

Related Non-Members

QDataStream &operator<<(QDataStream & s, const QPalette & p)
QDataStream &operator>>(QDataStream & s, QPalette & p)

Detailed Description

TheQPalette class contains color groups for each widget state.

A palette consists of three color groups:Active,Disabled, andInactive. 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 calledinaccessible orgrayed 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 withsetColor() 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 documentation.

We strongly recommend that you use the default palette of the current style (returned byQApplication::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 functionssetColor() andsetBrush(), depending on whether you want a pure color or a pixmap pattern.

There are also correspondingcolor() andbrush() getters, and a commonly used convenience function to get theColorRole for the currentColorGroup:window(),windowText(),base(), etc.

You can copy a palette using the copy constructor and test to see if two palettes areidentical usingisCopyOf().

QPalette is optimized by the use ofimplicit sharing, so it is very efficient to passQPalette 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 Mac OS X styles.

See alsoQApplication::setPalette(),QWidget::setPalette(), andQColor.

Member Type Documentation

enum QPalette::ColorGroup

ConstantValueDescription
QPalette::Disabled1 
QPalette::Active0 
QPalette::Inactive2 
QPalette::NormalActivesynonym for Active

enum QPalette::ColorRole

Color Roles

The ColorRole enum defines the different symbolic color roles used in current GUIs.

The central roles are:

ConstantValueDescription
QPalette::Window10A general background color.
QPalette::BackgroundWindowThis value is obsolete. Use Window instead.
QPalette::WindowText0A general foreground color.
QPalette::ForegroundWindowTextThis value is obsolete. Use WindowText instead.
QPalette::Base9Used 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::AlternateBase16Used as the alternate background color in views with alternating row colors (seeQAbstractItemView::setAlternatingRowColors()).
QPalette::ToolTipBase18Used as the background color forQToolTip andQWhatsThis. Tool tips use the Inactive color group ofQPalette, because tool tips are not active windows.
QPalette::ToolTipText19Used as the foreground color forQToolTip andQWhatsThis. Tool tips use the Inactive color group ofQPalette, because tool tips are not active windows.
QPalette::Text6The foreground color used withBase. This is usually the same as theWindowText, in which case it must provide good contrast withWindow andBase.
QPalette::Button1The general button background color. This background can be different fromWindow as some styles require a different background color for buttons.
QPalette::ButtonText8A foreground color used with theButton color.
QPalette::BrightText7A text color that is very different fromWindowText, and contrasts well with e.g.Dark. Typically used for text that needs to be drawn whereText orWindowText would give poor contrast, such as on pressed push buttons. Note that text colors can be used for things other than just words; text colors areusually 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 fromWindow, 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 onMid to be slightly different fromWindow.

ConstantValueDescription
QPalette::Light2Lighter thanButton color.
QPalette::Midlight3BetweenButton andLight.
QPalette::Dark4Darker thanButton.
QPalette::Mid5BetweenButton andDark.
QPalette::Shadow11A very dark color. By default, the shadow color isQt::black.

Selected (marked) items have two roles:

ConstantValueDescription
QPalette::Highlight12A color to indicate a selected item or the current item. By default, the highlight color isQt::darkBlue.
QPalette::HighlightedText13A text color that contrasts withHighlight. By default, the highlighted text color isQt::white.

There are two color roles related to hyperlinks:

ConstantValueDescription
QPalette::Link14A text color used for unvisited hyperlinks. By default, the link color isQt::blue.
QPalette::LinkVisited15A text color used for already visited hyperlinks. By default, the linkvisited color isQt::magenta.

Note that we do not use theLink andLinkVisited roles when rendering rich text in Qt, and that we recommend that you use CSS and theQTextDocument::setDefaultStyleSheet() function to alter the appearance of links. For example:

QTextBrowser browser;QColor linkColor(Qt::red);QString sheet=QString::fromLatin1("a { text-decoration: underline; color: %1 }").arg(linkColor.name());    browser.document()->setDefaultStyleSheet(sheet);
ConstantValueDescription
QPalette::NoRole17No role; this special role is often used to indicate that a role has not been assigned.

Member Function Documentation

QPalette::QPalette()

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

See alsoQApplication::setPalette() andQApplication::palette().

QPalette::QPalette(constQColor & button)

Constructs a palette from thebutton color. The other colors are automatically calculated, based on this color.Window will be the button color as well.

QPalette::QPalette(Qt::GlobalColor button)

Constructs a palette from thebutton color. The other colors are automatically calculated, based on this color.Window will be the button color as well.

QPalette::QPalette(constQColor & button, constQColor & window)

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

QPalette::QPalette(constQBrush & windowText, constQBrush & button, constQBrush & light, constQBrush & dark, constQBrush & mid, constQBrush & text, constQBrush & bright_text, constQBrush & base, constQBrush & window)

Constructs a palette. You can pass either brushes, pixmaps or plain colors forwindowText,button,light,dark,mid,text,bright_text,base andwindow.

See alsoQBrush.

QPalette::QPalette(constQPalette & p)

Constructs a copy ofp.

This constructor is fast thanks toimplicit sharing.

QPalette::~QPalette()

Destroys the palette.

constQBrush & QPalette::alternateBase() const

Returns the alternate base brush of the current color group.

See alsoColorRole andbrush().

constQBrush & QPalette::base() const

Returns the base brush of the current color group.

See alsoColorRole andbrush().

constQBrush & QPalette::brightText() const

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

See alsoColorRole andbrush().

constQBrush & QPalette::brush(ColorGroup group,ColorRole role) const

Returns the brush in the specified colorgroup, used for the given colorrole.

See alsocolor(),setBrush(), andColorRole.

constQBrush & QPalette::brush(ColorRole role) const

This is an overloaded function.

Returns the brush that has been set for the given colorrole in the currentColorGroup.

See alsocolor(),setBrush(), andColorRole.

constQBrush & QPalette::button() const

Returns the button brush of the current color group.

See alsoColorRole andbrush().

constQBrush & QPalette::buttonText() const

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

See alsoColorRole andbrush().

qint64 QPalette::cacheKey() const

Returns a number that identifies the contents of thisQPalette object. DistinctQPalette objects can have the same key if they refer to the same contents.

The cacheKey() will change when the palette is altered.

constQColor & QPalette::color(ColorGroup group,ColorRole role) const

Returns the color in the specified colorgroup, used for the given colorrole.

See alsobrush(),setColor(), andColorRole.

constQColor & QPalette::color(ColorRole role) const

This is an overloaded function.

Returns the color that has been set for the given colorrole in the currentColorGroup.

See alsobrush() andColorRole.

ColorGroup QPalette::currentColorGroup() const

Returns the palette's current color group.

See alsosetCurrentColorGroup().

constQBrush & QPalette::dark() const

Returns the dark brush of the current color group.

See alsoColorRole andbrush().

constQBrush & QPalette::highlight() const

Returns the highlight brush of the current color group.

See alsoColorRole andbrush().

constQBrush & QPalette::highlightedText() const

Returns the highlighted text brush of the current color group.

See alsoColorRole andbrush().

bool QPalette::isBrushSet(ColorGroup cg,ColorRole cr) const

Returns true if theColorGroupcg andColorRolecr has been set previously on this palette; otherwise returns false.

This function was introduced in Qt 4.2.

See alsosetBrush().

bool QPalette::isCopyOf(constQPalette & p) const

Returns true if this palette andp 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 alsooperator=() andoperator==().

bool QPalette::isEqual(ColorGroup cg1,ColorGroup cg2) const

Returns true (usually quickly) if color groupcg1 is equal tocg2; otherwise returns false.

constQBrush & QPalette::light() const

Returns the light brush of the current color group.

See alsoColorRole andbrush().

constQBrush & QPalette::link() const

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

See alsoColorRole andbrush().

constQBrush & QPalette::linkVisited() const

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

See alsoColorRole andbrush().

constQBrush & QPalette::mid() const

Returns the mid brush of the current color group.

See alsoColorRole andbrush().

constQBrush & QPalette::midlight() const

Returns the midlight brush of the current color group.

See alsoColorRole andbrush().

QPalette QPalette::resolve(constQPalette & other) const

Returns a newQPalette that has attributes copied fromother.

void QPalette::setBrush(ColorRole role, constQBrush & brush)

Sets the brush for the given colorrole to the specifiedbrush for all groups in the palette.

See alsobrush(),setColor(), andColorRole.

void QPalette::setBrush(ColorGroup group,ColorRole role, constQBrush & brush)

This is an overloaded function.

Sets the brush in the specified colorgroup, used for the given colorrole, tobrush.

See alsobrush(),setColor(), andColorRole.

void QPalette::setColor(ColorGroup group,ColorRole role, constQColor & color)

Sets the color in the specified colorgroup, used for the given colorrole, to the specified solidcolor.

See alsosetBrush(),color(), andColorRole.

void QPalette::setColor(ColorRole role, constQColor & color)

This is an overloaded function.

Sets the color used for the given colorrole, in all color groups, to the specified solidcolor.

See alsobrush(),setColor(), andColorRole.

void QPalette::setColorGroup(ColorGroup cg, constQBrush & windowText, constQBrush & button, constQBrush & light, constQBrush & dark, constQBrush & mid, constQBrush & text, constQBrush & bright_text, constQBrush & base, constQBrush & window)

Sets a the group atcg. You can pass either brushes, pixmaps or plain colors forwindowText,button,light,dark,mid,text,bright_text,base andwindow.

See alsoQBrush.

void QPalette::setCurrentColorGroup(ColorGroup cg)

Set the palette's current color group tocg.

See alsocurrentColorGroup().

constQBrush & QPalette::shadow() const

Returns the shadow brush of the current color group.

See alsoColorRole andbrush().

constQBrush & QPalette::text() const

Returns the text foreground brush of the current color group.

See alsoColorRole andbrush().

constQBrush & QPalette::toolTipBase() const

Returns the tool tip base brush of the current color group. This brush is used byQToolTip andQWhatsThis.

Note:Tool tips use the Inactive color group ofQPalette, because tool tips are not active windows.

This function was introduced in Qt 4.4.

See alsoColorRole andbrush().

constQBrush & QPalette::toolTipText() const

Returns the tool tip text brush of the current color group. This brush is used byQToolTip andQWhatsThis.

Note:Tool tips use the Inactive color group ofQPalette, because tool tips are not active windows.

This function was introduced in Qt 4.4.

See alsoColorRole andbrush().

constQBrush & QPalette::window() const

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

See alsoColorRole andbrush().

constQBrush & QPalette::windowText() const

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

See alsoColorRole andbrush().

QPalette::operator QVariant() const

Returns the palette as aQVariant

bool QPalette::operator!=(constQPalette & p) const

Returns true (slowly) if this palette is different fromp; otherwise returns false (usually quickly).

Note:The currentColorGroup is not taken into account when comparing palettes

See alsooperator==().

QPalette & QPalette::operator=(constQPalette & p)

Assignsp to this palette and returns a reference to this palette.

This operation is fast thanks toimplicit sharing.

QPalette & QPalette::operator=(QPalette && other)

bool QPalette::operator==(constQPalette & p) const

Returns true (usually quickly) if this palette is equal top; otherwise returns false (slowly).

Note:The currentColorGroup is not taken into account when comparing palettes

See alsooperator!=().

Related Non-Members

QDataStream &operator<<(QDataStream & s, constQPalette & p)

Writes the palette,p to the streams and returns a reference to the stream.

See alsoFormat of the QDataStream operators.

QDataStream &operator>>(QDataStream & s,QPalette & p)

Reads a palette from the stream,s into the palettep, and returns a reference to the stream.

See alsoFormat of the QDataStream operators.

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.


[8]ページ先頭

©2009-2025 Movatter.jp