返回介绍

QCustomMenuItem Class

发布于 2019-10-04 14:59:11 字数 4110 浏览 864 评论 0 收藏 0

The QCustomMenuItem class is an abstract base class for custom menu items in popup menus. More...

#include <qmenudata.h>

Inherits Qt.

List of all member functions.

Public Members

  • QCustomMenuItem ()
  • virtual ~QCustomMenuItem ()
  • virtual bool fullSpan () const
  • virtual bool isSeparator () const
  • virtual void setFont ( constQFont&font )
  • virtual void paint ( QPainter*p, constQColorGroup&cg, boolact, boolenabled, intx, inty, intw, inth ) = 0
  • virtual QSize sizeHint () = 0

Detailed Description

The QCustomMenuItem class is an abstract base class for custom menu items in popup menus.

A custom menu item is a menu item that is defined by two purely virtual functions, paint() and sizeHint(). The size hint tells the menu how much space it needs to reserve for this item, and paint is called whenever the item needs painting.

This simple mechanism allows you to create all kinds of application specific menu items. Examples are items showing different fonts in a word processor or menus that allow the selection of drawing utilities in a vector drawing program.

A custom item is inserted into a popup menu with QPopupMenu::insertItem().

By default, a custom item can also have an icon set and a keyboard accelerator. You can reimplement fullSpan() to return TRUE if you want the item to span the entire popup menu width. This is particularly useful for labels.

If you want the custom item to be treated just as a separator, reimplement isSeparator() to return TRUE.

Note that you can insert pixmaps or bitmaps as items into a popup menu without needing to create a QCustomMenuItem. However, custom menu items offer more flexibility, and -- especially important with windows style -- provide the possibility of drawing the item with a different color when it is highlighted.

menu/menu.cpp shows a simply example how custom menu items can be used.

Please note: the current implementation of QCustomMenuItem will not recognize shortcut keys that are from text with ampersands. Normal accelerators work though.

See also QMenuData, QPopupMenu and Miscellaneous Classes.


Member Function Documentation

QCustomMenuItem::QCustomMenuItem ()

Constructs a QCustomMenuItem

QCustomMenuItem::~QCustomMenuItem () [virtual]

Destroys a QCustomMenuItem

bool QCustomMenuItem::fullSpan () const [virtual]

Returns TRUE if this item wants to span the entire popup menu width. The default is FALSE, meaning that the menu may show an icon and an accelerator key for this item as well.

bool QCustomMenuItem::isSeparator () const [virtual]

Returns TRUE if this item is just a separator; otherwise returns FALSE.

void QCustomMenuItem::paint ( QPainter*p, constQColorGroup&cg, boolact, boolenabled, intx, inty, intw, inth ) [pure virtual]

Paints this item. When this function is invoked, the painter p is set to the right font and the right foreground color suitable for a menu item text using color group cg. The item is active if act is TRUE and enabled if enabled is TRUE. The geometry values x, y, w and h specify where to draw the item.

Do not draw any background, this has already been done by the popup menu according to the current GUI style.

void QCustomMenuItem::setFont ( constQFont&font ) [virtual]

Sets the font of the custom menu item to font.

This function is called whenever the font in the popup menu changes. For menu items that show their own individual font entry, you want to ignore this.

QSize QCustomMenuItem::sizeHint () [pure virtual]

Returns the size hint of this item.

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

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

发布评论

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