返回介绍

QPalette Class

发布于 2019-10-04 15:01:57 字数 11496 浏览 842 评论 0 收藏 0

The QPalette class contains color groups for each widget state. More...

#include <qpalette.h>

List of all member functions.

Public Members

  • QPalette ()
  • QPalette ( constQColor&button ) (obsolete)
  • QPalette ( constQColor&button, constQColor&background )
  • QPalette ( constQColorGroup&active, constQColorGroup&disabled, constQColorGroup&inactive )
  • QPalette ( constQPalette&p )
  • ~QPalette ()
  • QPalette & operator= ( constQPalette&p )
  • enum ColorGroup { Disabled, Active, Inactive, NColorGroups, Normal = Active }
  • const QColor & color ( ColorGroupgr, QColorGroup::ColorRoler ) const
  • const QBrush & brush ( ColorGroupgr, QColorGroup::ColorRoler ) const
  • void setColor ( ColorGroupgr, QColorGroup::ColorRoler, constQColor&c )
  • void setBrush ( ColorGroupgr, QColorGroup::ColorRoler, constQBrush&b )
  • void setColor ( QColorGroup::ColorRoler, constQColor&c )
  • void setBrush ( QColorGroup::ColorRoler, constQBrush&b )
  • QPalette copy () const
  • const QColorGroup & active () const
  • const QColorGroup & disabled () const
  • const QColorGroup & inactive () const
  • const QColorGroup & normal () const (obsolete)
  • void setActive ( constQColorGroup&g )
  • void setDisabled ( constQColorGroup&g )
  • void setInactive ( constQColorGroup&g )
  • void setNormal ( constQColorGroup&cg ) (obsolete)
  • bool operator== ( constQPalette&p ) const
  • bool operator!= ( constQPalette&p ) const
  • bool isCopyOf ( constQPalette&p )
  • int serialNumber () const

Related Functions

  • QDataStream & operator<< ( QDataStream&s, constQPalette&p )
  • QDataStream & operator>> ( QDataStream&s, QPalette&p )

Detailed Description

The QPalette class contains color groups for each widget state.

A palette consists of three color groups: active, disabled, and inactive. All widgets contain a palette, and all widgets in Qt 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 Motif style, active() and inactive() look the same. In Windows 2000 style and Macintosh Platinum style, the two styles look slightly different.

There are setActive(), setInactive(), and setDisabled() functions to modify the palette. (Qt also supports a normal() group; this is an obsolete alias for active(), supported for backwards compatibility.)

Colors and brushes can be set for particular roles in any of a palette's color groups with setColor() and setBrush().

You can copy a palette using the copy constructor and test to see if two palettes are identical using isCopyOf().

See also QApplication::setPalette(), QWidget::palette, QColorGroup, QColor, Widget Appearance and Style, Graphics Classes, Image Processing Classes and Implicitly and Explicitly Shared Classes.


Member Type Documentation

QPalette::ColorGroup

  • QPalette::Disabled
  • QPalette::Active
  • QPalette::Inactive
  • QPalette::NColorGroups
  • QPalette::Normal - synonym for Active

Member Function Documentation

QPalette::QPalette ()

Constructs a palette that consists of color groups with only black colors.

QPalette::QPalette ( constQColor&button )

This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.

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

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

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

QPalette::QPalette ( constQColorGroup&active, constQColorGroup&disabled, constQColorGroup&inactive )

Constructs a palette that consists of the three color groups active, disabled and inactive. See the Detailed Description for definitions of the color groups and QColorGroup::ColorRole for definitions of each color role in the three groups.

See also QColorGroup and QColorGroup::ColorRole.

QPalette::QPalette ( constQPalette&p )

Constructs a copy of p.

This constructor is fast (it uses copy-on-write).

QPalette::~QPalette ()

Destroys the palette.

constQColorGroup& QPalette::active () const

Returns the active color group of this palette.

See also QColorGroup, setActive(), inactive() and disabled().

Examples: themes/metal.cpp and themes/wood.cpp.

constQBrush& QPalette::brush ( ColorGroupgr, QColorGroup::ColorRoler ) const

Returns the brush in color group gr, used for color role r.

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

constQColor& QPalette::color ( ColorGroupgr, QColorGroup::ColorRoler ) const

Returns the color in color group gr, used for color role r.

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

QPalette QPalette::copy () const

Returns a deep copy of this palette.

Warning: This is slower than the copy constructor and assignment operator and offers no benefits.

constQColorGroup& QPalette::disabled () const

Returns the disabled color group of this palette.

See also QColorGroup, setDisabled(), active() and inactive().

Examples: themes/metal.cpp and themes/wood.cpp.

constQColorGroup& QPalette::inactive () const

Returns the inactive color group of this palette.

See also QColorGroup, setInactive(), active() and disabled().

bool QPalette::isCopyOf ( constQPalette&p )

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

constQColorGroup& QPalette::normal () const

This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.

Returns the active color group. Use active() instead.

See also setActive() and active().

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

Returns TRUE (slowly) if this palette is different from p; otherwise returns FALSE (usually quickly).

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

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

This is fast (it uses copy-on-write).

See also copy().

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

Returns TRUE (usually quickly) if this palette is equal to p; otherwise returns FALSE (slowly).

int QPalette::serialNumber () const

Returns a number that uniquely identifies this QPalette object. The serial number is intended for caching. Its value may not be used for anything other than equality testing.

Note that QPalette uses copy-on-write, and the serial number changes during the lazy copy operation (detach()), not during a shallow copy (copy constructor or assignment).

See also QPixmap, QPixmapCache and QCache.

void QPalette::setActive ( constQColorGroup&g )

Sets the Active color group to g.

See also active(), setDisabled(), setInactive() and QColorGroup.

void QPalette::setBrush ( ColorGroupgr, QColorGroup::ColorRoler, constQBrush&b )

Sets the brush in color group gr, used for color role r, to b.

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

void QPalette::setBrush ( QColorGroup::ColorRoler, constQBrush&b )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Sets the brush in for color role r in all three color groups to b.

See also brush(), setColor(), QColorGroup::ColorRole, active(), inactive() and disabled().

void QPalette::setColor ( ColorGroupgr, QColorGroup::ColorRoler, constQColor&c )

Sets the brush in color group gr, used for color role r, to the solid color c.

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

Example: themes/themes.cpp.

void QPalette::setColor ( QColorGroup::ColorRoler, constQColor&c )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Sets the brush color used for color role r to color c in all three color groups.

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

void QPalette::setDisabled ( constQColorGroup&g )

Sets the Disabled color group to g.

See also disabled(), setActive() and setInactive().

void QPalette::setInactive ( constQColorGroup&g )

Sets the Inactive color group to g.

See also active(), setDisabled(), setActive() and QColorGroup.

void QPalette::setNormal ( constQColorGroup&cg )

This function is obsolete. It is provided to keep old source working. We strongly advise against using it in new code.

Sets the active color group to cg. Use setActive() instead.

See also setActive() and active().


Related Functions

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

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

See also Format of the QDataStream operators.

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

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

See also Format of the QDataStream operators.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文