| Classes - Annotated - Tree - Functions - Home - Structure

# QCustomMenuItem Class Reference

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 ( const QFont & font )
- virtual void paint ( QPainter * p, const QColorGroup & cg, bool act, bool enabled, int x, int y, int w, int h )
- virtual QSize sizeHint ()

## 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, whereas paint is called whenever the item needs painting.

This simply mechanism gives applications the possibility 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().

Per default, a custom item can also have an icon set and/or an accelerator key. You can, however, reimplement fullSpan() to return TRUE if you want the item to span the entire popup menu width. This is in particular useful for labels.

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

Note that you can also insert pixmaps or bitmaps as items into a popup menu. A custom menu item, however, offers even more flexibility and - which is especially important under windows style - the possibility to draw the item with a different color when it is highlighted.

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

See also QMenuData and QPopupMenu.

## Member Function Documentation

### QCustomMenuItem::QCustomMenuItem ()

Constructs a QCustomMenuItem.

### QCustomMenuItem::~QCustomMenuItem () `[virtual]`

Destructs a QCustomMenuItem.

### bool QCustomMenuItem::fullSpan () const `[virtual]`

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

### bool QCustomMenuItem::isSeparator () const `[virtual]`

Returns whether this item is just a separator.

### void QCustomMenuItem::paint ( QPainter * p, const QColorGroup & cg, bool act, bool enabled, int x, int y, int w, int h ) `[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. The item is active according to act and enabled/disabled according to enabled. 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 ( const QFont & ) `[virtual]`

Sets the font of the custom menu item.

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 () `[virtual]`

Returns the size hint of this item.

Search the documentation, FAQ, qt-interest archive and more (uses www.trolltech.com):

This file is part of the Qt toolkit, copyright © 1995-2000 Trolltech, all rights reserved.