Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions

TQCustomMenuItem Class Reference

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

#include <ntqmenudata.h>

Inherits TQt.

List of all member functions.

Public Members


Detailed Description

The TQCustomMenuItem 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 pure 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 TQPopupMenu::insertItem().

By default, a custom item can also have an icon 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 TQCustomMenuItem. 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 simple example how custom menu items can be used.

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

See also TQMenuData, TQPopupMenu, and Miscellaneous Classes.


Member Function Documentation

TQCustomMenuItem::TQCustomMenuItem ()

Constructs a TQCustomMenuItem

TQCustomMenuItem::~TQCustomMenuItem () [virtual]

Destroys a TQCustomMenuItem

bool TQCustomMenuItem::fullSpan () const [virtual]

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

bool TQCustomMenuItem::isSeparator () const [virtual]

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

void TQCustomMenuItem::paint ( TQPainter * p, const TQColorGroup & cg, bool act, bool enabled, int x, int y, int w, int h ) [pure virtual]

Paints this item. When this function is invoked, the painter p is set to a font and 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 TQCustomMenuItem::setFont ( const TQFont & 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.

TQSize TQCustomMenuItem::sizeHint () [pure virtual]

Returns the item's size hint.


This file is part of the TQt toolkit. Copyright © 1995-2007 Trolltech. All Rights Reserved.


Copyright © 2007 TrolltechTrademarks
TQt 3.3.8